diff options
| author | Armand Philippot <git@armandphilippot.com> | 2022-01-11 13:04:50 +0100 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2022-01-11 15:33:04 +0100 |
| commit | 3d35170404b280bb70913ef41b0478ca65e00d72 (patch) | |
| tree | dc4e97cde6f1c2de84a2a84025cabaa59820ea33 /src/components | |
| parent | 67d94ce796e425f1a87806b848f58328ea7adde7 (diff) | |
chore(widget): pass title to TopicsList as parameter
I also choose to no display the current topic in the list if the
current page is a subject.
Diffstat (limited to 'src/components')
| -rw-r--r-- | src/components/Widget/TopicsList/TopicsList.tsx | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/components/Widget/TopicsList/TopicsList.tsx b/src/components/Widget/TopicsList/TopicsList.tsx index 179d129..6ddb186 100644 --- a/src/components/Widget/TopicsList/TopicsList.tsx +++ b/src/components/Widget/TopicsList/TopicsList.tsx @@ -1,10 +1,17 @@ import { t } from '@lingui/macro'; import { getAllSubjects } from '@services/graphql/queries'; import Link from 'next/link'; +import { useRouter } from 'next/router'; import useSWR from 'swr'; import styles from '../Widget.module.scss'; -const TopicsList = () => { +const TopicsList = ({ title }: { title: string }) => { + const router = useRouter(); + const isTopic = () => router.asPath.includes('/sujet/'); + const currentTopicSlug = isTopic() + ? router.asPath.replace('/sujet/', '') + : ''; + const { data, error } = useSWR('/api/subjects', getAllSubjects); if (error) return <div>{t`Failed to load.`}</div>; @@ -15,18 +22,20 @@ const TopicsList = () => { ); const subjects = sortedSubjects.map((subject) => { - return ( + return currentTopicSlug !== subject.slug ? ( <li key={subject.databaseId}> <Link href={`/sujet/${subject.slug}`}> <a>{subject.title}</a> </Link> </li> + ) : ( + '' ); }); return ( <div> - <h2 className={styles.title}>{t`Topics`}</h2> + <h2 className={styles.title}>{title}</h2> <ul className={styles.list}>{subjects}</ul> </div> ); |
