From 77d67e29ebcee7c160ba4e3972605473ab33bf14 Mon Sep 17 00:00:00 2001 From: Kamran Ahmed Date: Mon, 25 Mar 2024 15:11:05 +0000 Subject: [PATCH] fix: progress overflows the roadmap with --- src/components/Activity/ActivityPage.tsx | 83 +++++++++++++++++------- 1 file changed, 59 insertions(+), 24 deletions(-) diff --git a/src/components/Activity/ActivityPage.tsx b/src/components/Activity/ActivityPage.tsx index da8da197d..354a0bdae 100644 --- a/src/components/Activity/ActivityPage.tsx +++ b/src/components/Activity/ActivityPage.tsx @@ -52,7 +52,7 @@ export function ActivityPage() { async function loadActivity() { const { error, response } = await httpGet( - `${import.meta.env.PUBLIC_API_URL}/v1-get-user-stats` + `${import.meta.env.PUBLIC_API_URL}/v1-get-user-stats`, ); if (!response || error) { @@ -79,6 +79,25 @@ export function ActivityPage() { return null; } + const learningRoadmapsToShow = learningRoadmaps + .sort((a, b) => { + const updatedAtA = new Date(a.updatedAt); + const updatedAtB = new Date(b.updatedAt); + + return updatedAtB.getTime() - updatedAtA.getTime(); + }) + .filter((roadmap) => roadmap.learning > 0 || roadmap.done > 0); + + const learningBestPracticesToShow = learningBestPractices + .sort((a, b) => { + const updatedAtA = new Date(a.updatedAt); + const updatedAtB = new Date(b.updatedAt); + + return updatedAtB.getTime() - updatedAtA.getTime(); + }) + .filter((bestPractice) => bestPractice.learning > 0 || bestPractice.done > 0); + + return ( <>
- {learningRoadmaps.length === 0 && - learningBestPractices.length === 0 && } + {learningRoadmapsToShow.length === 0 && + learningBestPracticesToShow.length === 0 && } - {(learningRoadmaps.length > 0 || learningBestPractices.length > 0) && ( + {(learningRoadmapsToShow.length > 0 || learningBestPracticesToShow.length > 0) && ( <>

Continue Following @@ -104,26 +123,38 @@ export function ActivityPage() { return updatedAtB.getTime() - updatedAtA.getTime(); }) - .map((roadmap) => ( - { - pageProgressMessage.set('Updating activity'); - loadActivity().finally(() => { - pageProgressMessage.set(''); - }); - }} - /> - ))} + .filter((roadmap) => roadmap.learning > 0 || roadmap.done > 0) + .map((roadmap) => { + const learningCount = roadmap.learning || 0; + const doneCount = roadmap.done || 0; + const totalCount = roadmap.total || 0; + const skippedCount = roadmap.skipped || 0; + + return ( + totalCount ? totalCount : doneCount + } + learningCount={ + learningCount > totalCount ? totalCount : learningCount + } + totalCount={totalCount} + skippedCount={skippedCount} + resourceId={roadmap.id} + resourceType={'roadmap'} + updatedAt={roadmap.updatedAt} + title={roadmap.title} + onCleared={() => { + pageProgressMessage.set('Updating activity'); + loadActivity().finally(() => { + pageProgressMessage.set(''); + }); + }} + /> + ); + })} {learningBestPractices .sort((a, b) => { @@ -132,6 +163,10 @@ export function ActivityPage() { return updatedAtB.getTime() - updatedAtA.getTime(); }) + .filter( + (bestPractice) => + bestPractice.learning > 0 || bestPractice.done > 0, + ) .map((bestPractice) => (