From 67c445c2466d5b84a1efaa7998ae424ff3729276 Mon Sep 17 00:00:00 2001 From: Wiktoria Salamon <39302106+wiktoriasalamon@users.noreply.github.com> Date: Mon, 1 Jul 2024 15:16:25 +0200 Subject: [PATCH] [FE][CPF-69] Sidebar navigation routing (#70) * feat: sidebar navigation * linter * feat: add logo for collapsed sidebar * linter * fix: ts error * fix: typo * refactor: move routes to global constants * linter --- frontend/src/app/(app)/documentation/page.tsx | 7 ++ .../(app)/library/[ladder]/[bucket]/page.tsx | 7 +- .../src/app/(app)/library/[ladder]/page.tsx | 7 +- frontend/src/app/(app)/my-space/page.tsx | 7 ++ frontend/src/app/(app)/people/page.tsx | 7 ++ .../common/BucketCard/BucketCard.interface.ts | 1 + .../common/BucketCard/BucketCard.tsx | 5 +- .../common/LadderCard/LadderCard.tsx | 3 +- .../LadderDetails/LadderDetails.interface.ts | 1 + .../modules/LadderDetails/LadderDetails.tsx | 4 +- .../LibraryDetailed.interface.ts | 1 + .../LibraryDetailed/LibraryDetailed.tsx | 9 ++- .../components/modules/Sidebar/Sidebar.tsx | 71 ++++++++++--------- .../Sidebar/{utils.ts => constants.ts} | 16 +++-- frontend/src/constants/index.ts | 1 + frontend/src/constants/routes.ts | 15 ++++ 16 files changed, 107 insertions(+), 55 deletions(-) create mode 100644 frontend/src/app/(app)/documentation/page.tsx create mode 100644 frontend/src/app/(app)/my-space/page.tsx create mode 100644 frontend/src/app/(app)/people/page.tsx rename frontend/src/components/modules/Sidebar/{utils.ts => constants.ts} (65%) create mode 100644 frontend/src/constants/index.ts create mode 100644 frontend/src/constants/routes.ts diff --git a/frontend/src/app/(app)/documentation/page.tsx b/frontend/src/app/(app)/documentation/page.tsx new file mode 100644 index 00000000..8fdac895 --- /dev/null +++ b/frontend/src/app/(app)/documentation/page.tsx @@ -0,0 +1,7 @@ +export default function Documentation() { + return ( +
+

Documentation

+
+ ); +} diff --git a/frontend/src/app/(app)/library/[ladder]/[bucket]/page.tsx b/frontend/src/app/(app)/library/[ladder]/[bucket]/page.tsx index 69213838..70dc36bd 100644 --- a/frontend/src/app/(app)/library/[ladder]/[bucket]/page.tsx +++ b/frontend/src/app/(app)/library/[ladder]/[bucket]/page.tsx @@ -2,6 +2,7 @@ import { Breadcrumbs } from '@app/components/modules/Breadcrumbs'; import { mapKeysToCamelCase } from '@app/utils'; import { BucketDetails } from '@app/components/modules/BucketDetails'; import { API_URLS } from '@app/api'; +import { routes } from '@app/constants'; async function getBucketDetails(slug: string) { const response = await fetch(`${API_URLS.library.buckets}/${slug}`); @@ -34,9 +35,9 @@ export default async function BucketDetailed({ params }: { params: { bucket: str
{data && } diff --git a/frontend/src/app/(app)/library/[ladder]/page.tsx b/frontend/src/app/(app)/library/[ladder]/page.tsx index 827d500a..9e70c416 100644 --- a/frontend/src/app/(app)/library/[ladder]/page.tsx +++ b/frontend/src/app/(app)/library/[ladder]/page.tsx @@ -2,6 +2,7 @@ import { Breadcrumbs } from '@app/components/modules/Breadcrumbs'; import { LibraryDetailed } from '@app/components/modules/LibraryDetailed'; import { mapKeysToCamelCase } from '@app/utils'; import { API_URLS } from '@app/api'; +import { routes } from '@app/constants'; async function getLadderDetails(slug: string) { const response = await fetch(`${API_URLS.library.ladders}/${slug}`); @@ -21,11 +22,11 @@ export default async function LadderDetailed({ params }: { params: { ladder: str
- {data && } + {data && }
); } diff --git a/frontend/src/app/(app)/my-space/page.tsx b/frontend/src/app/(app)/my-space/page.tsx new file mode 100644 index 00000000..f3fab3de --- /dev/null +++ b/frontend/src/app/(app)/my-space/page.tsx @@ -0,0 +1,7 @@ +export default function MySpace() { + return ( +
+

My Space

+
+ ); +} diff --git a/frontend/src/app/(app)/people/page.tsx b/frontend/src/app/(app)/people/page.tsx new file mode 100644 index 00000000..32645863 --- /dev/null +++ b/frontend/src/app/(app)/people/page.tsx @@ -0,0 +1,7 @@ +export default function People() { + return ( +
+

People

+
+ ); +} diff --git a/frontend/src/components/common/BucketCard/BucketCard.interface.ts b/frontend/src/components/common/BucketCard/BucketCard.interface.ts index 5c524e6b..95ca0751 100644 --- a/frontend/src/components/common/BucketCard/BucketCard.interface.ts +++ b/frontend/src/components/common/BucketCard/BucketCard.interface.ts @@ -1,5 +1,6 @@ import { LadderBandBucket } from '@app/types/common'; export interface BucketCardProps { + ladderSlug: string; bucket: LadderBandBucket; } diff --git a/frontend/src/components/common/BucketCard/BucketCard.tsx b/frontend/src/components/common/BucketCard/BucketCard.tsx index a3c98a1b..07580ebd 100644 --- a/frontend/src/components/common/BucketCard/BucketCard.tsx +++ b/frontend/src/components/common/BucketCard/BucketCard.tsx @@ -1,13 +1,14 @@ import Link from 'next/link'; import { BucketCardProps } from './BucketCard.interface'; import { ChevronRightIcon } from '@app/static/icons/ChevronRightIcon'; +import { routes } from '@app/constants'; -export const BucketCard = ({ bucket }: BucketCardProps) => { +export const BucketCard = ({ bucket, ladderSlug }: BucketCardProps) => { const { bucketSlug, bucketName, description } = bucket; return (
diff --git a/frontend/src/components/common/LadderCard/LadderCard.tsx b/frontend/src/components/common/LadderCard/LadderCard.tsx index 1264a208..21528538 100644 --- a/frontend/src/components/common/LadderCard/LadderCard.tsx +++ b/frontend/src/components/common/LadderCard/LadderCard.tsx @@ -1,9 +1,10 @@ import Link from 'next/link'; import { LadderCardInterface } from './LadderCard.interface'; +import { routes } from '@app/constants'; export const LadderCard = ({ ladderName, ladderSlug }: LadderCardInterface) => (

{ladderName}

diff --git a/frontend/src/components/modules/LadderDetails/LadderDetails.interface.ts b/frontend/src/components/modules/LadderDetails/LadderDetails.interface.ts index c90caeb5..7ff3d130 100644 --- a/frontend/src/components/modules/LadderDetails/LadderDetails.interface.ts +++ b/frontend/src/components/modules/LadderDetails/LadderDetails.interface.ts @@ -2,6 +2,7 @@ import { LadderBand } from '@app/types/common'; export interface LadderDetailsProps { ladder: LadderBand; + ladderSlug: string; ladderName: string; band: number; } diff --git a/frontend/src/components/modules/LadderDetails/LadderDetails.tsx b/frontend/src/components/modules/LadderDetails/LadderDetails.tsx index 12a6861b..4ff43c76 100644 --- a/frontend/src/components/modules/LadderDetails/LadderDetails.tsx +++ b/frontend/src/components/modules/LadderDetails/LadderDetails.tsx @@ -6,7 +6,7 @@ import { BucketCard } from '@app/components/common/BucketCard'; import { AccordionCard } from '@app/components/common/AccordionCard'; import { AccordionList } from '@app/components/common/AccordionList'; -export const LadderDetails = ({ ladder, ladderName, band }: LadderDetailsProps) => { +export const LadderDetails = ({ ladder, ladderName, band, ladderSlug }: LadderDetailsProps) => { return (
@@ -36,7 +36,7 @@ export const LadderDetails = ({ ladder, ladderName, band }: LadderDetailsProps)

Hard skills

{ladder.hardSkillBuckets.map((bucket: LadderBandBucket) => ( - + ))}
diff --git a/frontend/src/components/modules/LibraryDetailed/LibraryDetailed.interface.ts b/frontend/src/components/modules/LibraryDetailed/LibraryDetailed.interface.ts index dd44a488..e1977aa4 100644 --- a/frontend/src/components/modules/LibraryDetailed/LibraryDetailed.interface.ts +++ b/frontend/src/components/modules/LibraryDetailed/LibraryDetailed.interface.ts @@ -1,6 +1,7 @@ import { LadderBand } from '@app/types/common'; export interface LibraryDetailedProps { + ladderSlug: string; data: { ladderName: string; bands: Record; diff --git a/frontend/src/components/modules/LibraryDetailed/LibraryDetailed.tsx b/frontend/src/components/modules/LibraryDetailed/LibraryDetailed.tsx index 7f255227..ce508928 100644 --- a/frontend/src/components/modules/LibraryDetailed/LibraryDetailed.tsx +++ b/frontend/src/components/modules/LibraryDetailed/LibraryDetailed.tsx @@ -5,7 +5,7 @@ import { LadderTabs } from '@app/components/modules/LadderTabs'; import { LibraryDetailedProps } from './LibraryDetailed.interface'; import { useCallback, useEffect, useMemo, useState } from 'react'; -export const LibraryDetailed: React.FC = ({ data }) => { +export const LibraryDetailed: React.FC = ({ data, ladderSlug }) => { const router = useRouter(); const pathname = usePathname(); const searchParams = useSearchParams(); @@ -41,7 +41,12 @@ export const LibraryDetailed: React.FC = ({ data }) => {
- +
); diff --git a/frontend/src/components/modules/Sidebar/Sidebar.tsx b/frontend/src/components/modules/Sidebar/Sidebar.tsx index 5aadb906..1bad6b46 100644 --- a/frontend/src/components/modules/Sidebar/Sidebar.tsx +++ b/frontend/src/components/modules/Sidebar/Sidebar.tsx @@ -1,57 +1,58 @@ 'use client'; -import Image from 'next/image'; import Link from 'next/link'; import { generateClassNames } from '@app/utils'; -import { navigation } from './utils'; +import { navigation } from './constants'; import { ChevronDoubleLeft } from '@app/static/icons/ChevronDoubleLeft'; import { Button } from '@headlessui/react'; import { useState } from 'react'; +import { usePathname } from 'next/navigation'; const duration = 'duration-300' as const; export const Sidebar = () => { const [open, setOpen] = useState(true); + const pathname = usePathname(); const toggleSidebar = () => setOpen((prev) => !prev); return ( ); diff --git a/frontend/src/components/modules/Sidebar/utils.ts b/frontend/src/components/modules/Sidebar/constants.ts similarity index 65% rename from frontend/src/components/modules/Sidebar/utils.ts rename to frontend/src/components/modules/Sidebar/constants.ts index 3664a29d..6b2c5542 100644 --- a/frontend/src/components/modules/Sidebar/utils.ts +++ b/frontend/src/components/modules/Sidebar/constants.ts @@ -2,25 +2,27 @@ import { HomeIcon } from '@app/static/icons/HomeIcon'; import { PeopleIcon } from '@app/static/icons/PeopleIcon'; import { LayoutIcon } from '@app/static/icons/LayoutIcon'; import { DocumentIcon } from '@app/static/icons/DocumentIcon'; +import { routes } from '@app/constants'; export const navigation = [ - { name: 'My space', href: '#', current: false, icon: HomeIcon }, + { + name: 'My space', + href: routes.mySpace.index, + icon: HomeIcon, + }, { name: 'People', - href: '#', - current: false, + href: routes.people.index, icon: PeopleIcon, }, { name: 'CPF Library', - href: '/library', - current: true, + href: routes.library.index, icon: LayoutIcon, }, { name: 'Documentation', - href: '#', - current: false, + href: routes.documentation.index, icon: DocumentIcon, }, ]; diff --git a/frontend/src/constants/index.ts b/frontend/src/constants/index.ts new file mode 100644 index 00000000..57f46d7f --- /dev/null +++ b/frontend/src/constants/index.ts @@ -0,0 +1 @@ +export { routes } from './routes'; diff --git a/frontend/src/constants/routes.ts b/frontend/src/constants/routes.ts new file mode 100644 index 00000000..2d4c5d4e --- /dev/null +++ b/frontend/src/constants/routes.ts @@ -0,0 +1,15 @@ +export const routes = { + documentation: { + index: '/documentation', + }, + library: { + index: '/library', + }, + mySpace: { + index: '/my-space', + }, + people: { + index: '/people', + myProfile: '/people/my-profile', + }, +};