From 09fb526896d932e3db4d8591561a7cc02dec44af Mon Sep 17 00:00:00 2001 From: Arik Chakma Date: Sat, 31 Aug 2024 00:23:54 +0600 Subject: [PATCH] feat: dashboard favourite --- src/components/Activity/ProjectProgress.tsx | 10 ++- src/components/Dashboard/DashboardPage.tsx | 9 +- .../Dashboard/PersonalDashboard.tsx | 84 ++++++++++++++----- src/pages/dashboard.astro | 40 ++++++--- 4 files changed, 107 insertions(+), 36 deletions(-) diff --git a/src/components/Activity/ProjectProgress.tsx b/src/components/Activity/ProjectProgress.tsx index 22211e13f..6ac20de28 100644 --- a/src/components/Activity/ProjectProgress.tsx +++ b/src/components/Activity/ProjectProgress.tsx @@ -11,11 +11,15 @@ type ProjectProgressType = { title: string; }; showActions?: boolean; + userId?: string; }; export function ProjectProgress(props: ProjectProgressType) { - const { projectStatus, showActions = true } = props; - const userId = getUser()?.id; + const { + projectStatus, + showActions = true, + userId: defaultUserId = getUser()?.id, + } = props; const shouldShowActions = projectStatus.submittedAt && @@ -43,7 +47,7 @@ export function ProjectProgress(props: ProjectProgressType) { {shouldShowActions && (
diff --git a/src/components/Dashboard/DashboardPage.tsx b/src/components/Dashboard/DashboardPage.tsx index 9801283cd..869ff3e53 100644 --- a/src/components/Dashboard/DashboardPage.tsx +++ b/src/components/Dashboard/DashboardPage.tsx @@ -10,12 +10,14 @@ import { TeamDashboard } from './TeamDashboard'; import { getUser } from '../../lib/jwt'; type DashboardPageProps = { - builtInRoadmaps?: BuiltInRoadmap[]; + builtInRoleRoadmaps?: BuiltInRoadmap[]; + builtInSkillRoadmaps?: BuiltInRoadmap[]; builtInBestPractices?: BuiltInRoadmap[]; }; export function DashboardPage(props: DashboardPageProps) { - const { builtInRoadmaps, builtInBestPractices } = props; + const { builtInRoleRoadmaps, builtInBestPractices, builtInSkillRoadmaps } = + props; const currentUser = getUser(); const toast = useToast(); @@ -95,7 +97,8 @@ export function DashboardPage(props: DashboardPageProps) { {!selectedTeamId && ( )} diff --git a/src/components/Dashboard/PersonalDashboard.tsx b/src/components/Dashboard/PersonalDashboard.tsx index e03cf8ee7..1276e6396 100644 --- a/src/components/Dashboard/PersonalDashboard.tsx +++ b/src/components/Dashboard/PersonalDashboard.tsx @@ -8,6 +8,7 @@ import type { PageType } from '../CommandMenu/CommandMenu'; import { useToast } from '../../hooks/use-toast'; import { LoadingProgress } from './LoadingProgress'; import { ArrowUpRight, Pencil } from 'lucide-react'; +import { MarkFavorite } from '../FeaturedItems/MarkFavorite'; type UserDashboardResponse = { name: string; @@ -21,17 +22,24 @@ type UserDashboardResponse = { export type BuiltInRoadmap = { id: string; + url: string; title: string; description: string; + isFavorite?: boolean; }; type PersonalDashboardProps = { - builtInRoadmaps?: BuiltInRoadmap[]; + builtInRoleRoadmaps?: BuiltInRoadmap[]; + builtInSkillRoadmaps?: BuiltInRoadmap[]; builtInBestPractices?: BuiltInRoadmap[]; }; export function PersonalDashboard(props: PersonalDashboardProps) { - const { builtInRoadmaps = [], builtInBestPractices = [] } = props; + const { + builtInRoleRoadmaps = [], + builtInBestPractices = [], + builtInSkillRoadmaps = [], + } = props; const toast = useToast(); const [isLoading, setIsLoading] = useState(true); @@ -49,6 +57,17 @@ export function PersonalDashboard(props: PersonalDashboardProps) { return; } + progressList?.progresses?.forEach((progress) => { + window.dispatchEvent( + new CustomEvent('mark-favorite', { + detail: { + resourceId: progress.resourceId, + resourceType: progress.resourceType, + isFavorite: progress.isFavorite, + }, + }), + ); + }); setPersonalDashboardDetails(progressList); } @@ -74,12 +93,14 @@ export function PersonalDashboard(props: PersonalDashboardProps) { ); }, []); - const learningRoadmaps = - personalDashboardDetails?.progresses?.filter( - (progress) => progress.resourceType === 'roadmap', - ) || []; + useEffect(() => { + window.addEventListener('refresh-favorites', loadProgress); + return () => window.removeEventListener('refresh-favorites', loadProgress); + }, []); - const learningRoadmapsToShow = learningRoadmaps.sort((a, b) => { + const learningRoadmapsToShow = ( + personalDashboardDetails?.progresses || [] + ).sort((a, b) => { const updatedAtA = new Date(a.updatedAt); const updatedAtB = new Date(b.updatedAt); @@ -193,10 +214,10 @@ export function PersonalDashboard(props: PersonalDashboardProps) { totalCount={totalCount} skippedCount={skippedCount} resourceId={roadmap.resourceId} - resourceType="roadmap" + resourceType={roadmap.resourceType} updatedAt={roadmap.updatedAt} title={roadmap.resourceTitle} - showActions={false} + showActions={true} roadmapSlug={roadmap.roadmapSlug} /> ); @@ -213,7 +234,7 @@ export function PersonalDashboard(props: PersonalDashboardProps) { ); })} @@ -221,9 +242,14 @@ export function PersonalDashboard(props: PersonalDashboardProps) { )}

- All Roadmaps + Role Based Roadmaps

- + + +

+ Skill Based Roadmaps +

+

Best Practices @@ -242,23 +268,41 @@ export function ListRoadmaps(props: ListRoadmapsProps) { const [showAll, setShowAll] = useState(roadmaps.length <= 12); const roadmapsToShow = showAll ? roadmaps : roadmaps.slice(0, 12); + const [isMounted, setIsMounted] = useState(false); + useEffect(() => { + setIsMounted(true); + }, []); + return (
{roadmapsToShow.map((roadmap) => ( - - {roadmap.title} - +
+ + {roadmap.title} + + + {isMounted && ( + + )} +
))}
{!showAll && (
{ - const { frontmatter } = roadmap; +const enrichedRoleRoadmaps = roleRoadmaps + .filter((roadmapItem) => !roadmapItem.frontmatter.isHidden) + .map((roadmap) => { + const { frontmatter } = roadmap; + + return { + id: roadmap.id, + url: `/${roadmap.id}`, + title: frontmatter.briefTitle, + description: frontmatter.briefDescription, + }; + }); +const enrichedSkillRoadmaps = skillRoadmaps + .filter((roadmapItem) => !roadmapItem.frontmatter.isHidden) + .map((roadmap) => { + const { frontmatter } = roadmap; + + return { + id: roadmap.id, + url: `/${roadmap.id}`, + title: + frontmatter.briefTitle === 'Go' ? 'Go Roadmap' : frontmatter.briefTitle, + description: frontmatter.briefDescription, + }; + }); - return { - id: roadmap.id, - title: frontmatter.briefTitle, - description: frontmatter.briefDescription, - }; -}); const enrichedBestPractices = bestPractices.map((bestPractice) => { const { frontmatter } = bestPractice; return { id: bestPractice.id, + url: `/best-practices/${bestPractice.id}`, title: frontmatter.briefTitle, description: frontmatter.briefDescription, }; @@ -29,7 +48,8 @@ const enrichedBestPractices = bestPractices.map((bestPractice) => {