From 30b384f7ed620ff0d16c40b34251f1a088508774 Mon Sep 17 00:00:00 2001 From: cassandraGoose Date: Wed, 24 Apr 2024 21:20:12 -0600 Subject: [PATCH] setup other pages to handle the new pathway data layout --- app/_components/CompetencyCard.tsx | 26 +---- .../_components/PathwayProgressDetails.tsx | 107 +++++------------- .../PathwayProgressDetailsCompetencyList.tsx | 76 +++++++++++++ app/pathways/[pathway]/page.tsx | 36 ++++-- app/pathways/page.tsx | 24 +--- 5 files changed, 145 insertions(+), 124 deletions(-) create mode 100644 app/dashboard/[pathway]/_components/PathwayProgressDetailsCompetencyList.tsx diff --git a/app/_components/CompetencyCard.tsx b/app/_components/CompetencyCard.tsx index 8100241..fb221b1 100644 --- a/app/_components/CompetencyCard.tsx +++ b/app/_components/CompetencyCard.tsx @@ -5,32 +5,18 @@ export default function CompetencyCard({competency}: { competency: Competency }) return (
-
-

+

+

{competency.title}

-

{competency.description}

-
- {competency.contentAreas && - competency.contentAreas.map((contentArea: ContentArea) => { - return ( -
- {contentArea.title} -
- ); - })} -
+

{competency.description}

- {competency?.proofs?.length && (
+ {competency?.proofs?.length ? (

Proof of competency:

-
)} +
): null}
); } diff --git a/app/dashboard/[pathway]/_components/PathwayProgressDetails.tsx b/app/dashboard/[pathway]/_components/PathwayProgressDetails.tsx index 099084a..4016e93 100644 --- a/app/dashboard/[pathway]/_components/PathwayProgressDetails.tsx +++ b/app/dashboard/[pathway]/_components/PathwayProgressDetails.tsx @@ -1,91 +1,42 @@ -"use client"; - -import { useState } from "react"; -import { Competency, Pathway, ContentArea } from "../../../lib/interface"; -import Link from "next/link"; - -export default function PathwayProgressDetails({ pathway, pathwayId }: { pathway: Pathway, pathwayId: string }) { - const [collapsed, setCollapsed] = useState(false); +import { Fragment } from 'react'; +import { Competency, Pathway, ContentArea } from '../../../lib/interface'; +import PathwayProgressDetailsCompetencyList from './PathwayProgressDetailsCompetencyList'; +export default function PathwayProgressDetails({ + pathway, + pathwayId, +}: { + pathway: Pathway; + pathwayId: string; +}) { const totalCompetencies = pathway.contentAreas.reduce((acc, contentArea) => { - acc.push(...contentArea.competencies); - return acc; - }, [] as Competency[]); + acc.push(...contentArea.competencies); + return acc; + }, [] as Competency[]); const getCompletedCompetencies = (contentAreas: ContentArea[]) => { return totalCompetencies.reduce((acc, competency) => { if (competency.proofs && competency.proofs.length > 0) acc++; return acc; }, 0); - } - - const checkCompetencyCompleted = (competency: Competency) => { - return competency.proofs && competency.proofs.length > 0; - } + }; return ( -
-
-
-
-

- {getCompletedCompetencies(pathway.contentAreas)} / {totalCompetencies.length} competencies met -

- -
-
-
- - - - - - - - - - {totalCompetencies.map((competency: Competency) => ( - - - - - - - ))} - -
CompletedCompetencyDescription
- - {checkCompetencyCompleted(competency) ? '✓' : null} - - - -

{competency.title}

-
-
-

{competency.description}

-
- - Proof - -
-
-
+
+

+ {getCompletedCompetencies(pathway.contentAreas)} /{' '} + {totalCompetencies.length} competencies met +

+ {pathway.contentAreas.map((contentArea) => { + return ( + + + + ); + })}
); } diff --git a/app/dashboard/[pathway]/_components/PathwayProgressDetailsCompetencyList.tsx b/app/dashboard/[pathway]/_components/PathwayProgressDetailsCompetencyList.tsx new file mode 100644 index 0000000..a36bb83 --- /dev/null +++ b/app/dashboard/[pathway]/_components/PathwayProgressDetailsCompetencyList.tsx @@ -0,0 +1,76 @@ +'use client'; + +import { useState } from 'react'; +import Link from 'next/link'; +import { Competency, ContentArea } from '../../../lib/interface'; + +export default function PathwayProgressDetailsCompetencyList({ contentArea, pathwayId}: { contentArea: ContentArea, pathwayId: string }) { + const [collapsed, setCollapsed] = useState(false); + + const checkCompetencyCompleted = (competency: Competency) => { + return competency.proofs && competency.proofs.length > 0; + }; + + return (
+
+
+

{contentArea.title}

+ + +
+
+
+ + + + + + + + + + {contentArea.competencies.map((competency: Competency) => ( + + + + + + + ))} + +
CompletedCompetencyDescription
+ + {checkCompetencyCompleted(competency) ? '✓' : null} + + + +

{competency.title}

+
+
+

{competency.description}

+
+ + Proof + +
+
+
); +} \ No newline at end of file diff --git a/app/pathways/[pathway]/page.tsx b/app/pathways/[pathway]/page.tsx index 260fb54..385bc9b 100644 --- a/app/pathways/[pathway]/page.tsx +++ b/app/pathways/[pathway]/page.tsx @@ -22,7 +22,9 @@ export default async function Page({ let hasPathway; if (!!user) { userPathways = await getSingleUserPathway(singlePathway.id.toString()); - hasPathway = userPathways?.pathways.find((pathway) => pathway.id === singlePathway.id); + hasPathway = userPathways?.pathways.find( + (pathway) => pathway.id === singlePathway.id, + ); } return ( @@ -33,7 +35,12 @@ export default async function Page({

{singlePathway.title}

- {!!user && } + {!!user && ( + + )}

{singlePathway.description}

@@ -45,12 +52,27 @@ export default async function Page({ below by uploading artifacts (called 'proofs') to act as proof of your skills and knowledge.

-
- {singlePathway.competencies.map((competency) => { +
+ {singlePathway.contentAreas.map((contentArea) => { return ( - - - + <> +
+
+

{contentArea.title}

+
+ {contentArea.competencies.map((competency) => { + return ( + + + + ); + })} +
+
+ ); })}
diff --git a/app/pathways/page.tsx b/app/pathways/page.tsx index 9a95751..c3037b3 100644 --- a/app/pathways/page.tsx +++ b/app/pathways/page.tsx @@ -3,7 +3,7 @@ import { notFound } from 'next/navigation'; import Link from 'next/link'; import { getFilteredPathways, getFilteredPathwaysCount } from '../lib/queries'; import PathwayCard from '../_components/PathwayCard'; -import { Competency } from '../lib/interface'; +import { ContentArea } from '../lib/interface'; import ContentAreaPill from '../_components/ContentAreaPill'; import Search from '../_components/Search'; import Pagination from '../_components/Pagination'; @@ -24,28 +24,14 @@ export default async function Page({ notFound(); } - const createContentAreaList = (competencies: Competency[]) => { - if (!competencies) notFound(); - return competencies.map((competency) => { - if (!competency.contentAreas) notFound(); - - return competency.contentAreas.map((contentArea) => { - return { title: contentArea.title, parentId: competency.id }; - }); - }); - }; - - const createCardActionChild = (competencies: Competency[]) => { - const contentAreas = createContentAreaList(competencies); - + const createCardActionChild = (contentAreas: ContentArea[]) => { return (
{contentAreas - .flat() - .map((contentArea: { title: string; parentId: number }) => ( + .map((contentArea) => ( @@ -79,7 +65,7 @@ export default async function Page({ title={pathway.title} description={pathway.description} rightBlockChild={createRightBlockChild(pathway.id)} - cardActionChild={createCardActionChild(pathway.competencies)} + cardActionChild={createCardActionChild(pathway.contentAreas)} /> ); })}