Skip to content

Commit

Permalink
feat: add helpful links limit and styling to opc dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
calisio committed Dec 10, 2024
1 parent 73bd8cf commit 07440e4
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 12 deletions.
13 changes: 12 additions & 1 deletion frontend/src/Components/cards/HelpfulLinkCard.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
import { HelpfulLink, ModalType, ToastState, UserRole } from '@/common';
import {
HelpfulLink,
HelpfulLinkAndSort,
ModalType,
ServerResponseOne,
ToastState,
UserRole
} from '@/common';
import API from '@/api/api';
import VisibleHiddenToggle from '../VisibleHiddenToggle';
import { useState } from 'react';
import ULIComponent from '../ULIComponent';
import { PencilSquareIcon, TrashIcon } from '@heroicons/react/24/outline';
import { AdminRoles, useAuth } from '@/useAuth';
import { useToast } from '@/Context/ToastCtx';
import { KeyedMutator } from 'swr';

export default function HelpfulLinkCard({
link,
showModal,
mutate,
role
}: {
link: HelpfulLink;
showModal?: (link: HelpfulLink, type: ModalType) => void;
mutate?: KeyedMutator<ServerResponseOne<HelpfulLinkAndSort>>;
role?: UserRole;
}) {
const [visible, setVisible] = useState<boolean>(link.visibility_status);
Expand All @@ -35,6 +45,7 @@ export default function HelpfulLinkCard({
response.message,
response.success ? ToastState.success : ToastState.error
);
if (mutate) void mutate();
};

if (!user) {
Expand Down
1 change: 1 addition & 0 deletions frontend/src/Pages/HelpfulLinksManagement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export default function HelpfulLinksManagement() {
<HelpfulLinkCard
key={index}
link={link}
mutate={mutate}
showModal={showModifyLink}
/>
);
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/Pages/OpenContentLevelDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ export default function OpenContentLevelDashboard() {
</div>
</div>
<h2>Resources</h2>
<div className="card card-row-padding overflow-x-scroll no-scrollbar">
<div className="card card-row-padding grid grid-cols-5 gap-3">
{helpfulLinks.map((link: HelpfulLink) => (
<div
key={link.id}
className="w-[252px] cursor-pointer"
className="cursor-pointer"
onClick={(e) => {
e.preventDefault();
void handleHelpfulLinkClick(link.id);
Expand Down
29 changes: 20 additions & 9 deletions frontend/src/routeLoaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,28 @@ import {
OpenContentProvider,
ServerResponse,
HelpfulLink,
HelpfulLinkAndSort
HelpfulLinkAndSort,
Library
} from './common';
import API from './api/api';
import { fetchUser } from './useAuth';

export const getOpenContentDashboardData: LoaderFunction = async () => {
const user = await fetchUser();
if (!user) return;
const [resourcesResp, userContentResp, facilityContentResp, favoritesResp] =
await Promise.all([
API.get(`helpful-links?visibility=true`),
API.get(`open-content/activity/${user.id}`),
API.get(`open-content/activity`),
API.get(`open-content/favorites`)
]);
const [
resourcesResp,
userContentResp,
facilityContentResp,
favoritesResp,
featuredResp
] = await Promise.all([
API.get(`helpful-links?visibility=true&per_page=5`),
API.get(`open-content/activity/${user.id}`),
API.get(`open-content/activity`),
API.get(`open-content/favorites`),
API.get(`libraries?visibility=featured`)
]);

const links = resourcesResp.data as HelpfulLinkAndSort;
console.log('resourcesResp', resourcesResp.data as HelpfulLinkAndSort);
Expand All @@ -34,12 +41,16 @@ export const getOpenContentDashboardData: LoaderFunction = async () => {
const favoriteOpenContent = favoritesResp.success
? (favoritesResp.data as OpenContentFavorite[])
: [];
const featured = featuredResp.success
? (featuredResp.data as Library[])
: [];

return json({
helpfulLinks: helpfulLinks,
topUserContent: topUserOpenContent,
topFacilityContent: topFacilityOpenContent,
favorites: favoriteOpenContent
favorites: favoriteOpenContent,
featured: featured
});
};

Expand Down

0 comments on commit 07440e4

Please sign in to comment.