aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/Widget
diff options
context:
space:
mode:
authorArmand Philippot <git@armandphilippot.com>2022-01-11 11:41:58 +0100
committerArmand Philippot <git@armandphilippot.com>2022-01-11 11:41:58 +0100
commit98dd62e28793bad9c121a9f16b11a10222a41c50 (patch)
treecada79d3144685db218881c2913094c3613513d2 /src/components/Widget
parent5b1ecb1990463889bc736029fcbe38d0756141db (diff)
chore(widgets): pass title to thematics list as parameter
If the current page is a thematic, I also choose to not display the current thematic in the list.
Diffstat (limited to 'src/components/Widget')
-rw-r--r--src/components/Widget/ThematicsList/ThematicsList.tsx16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/components/Widget/ThematicsList/ThematicsList.tsx b/src/components/Widget/ThematicsList/ThematicsList.tsx
index 232515d..0dc0916 100644
--- a/src/components/Widget/ThematicsList/ThematicsList.tsx
+++ b/src/components/Widget/ThematicsList/ThematicsList.tsx
@@ -1,11 +1,17 @@
import { t } from '@lingui/macro';
import { getAllThematics } from '@services/graphql/queries';
-import { ThematicPreview } from '@ts/types/taxonomies';
import Link from 'next/link';
+import { useRouter } from 'next/router';
import useSWR from 'swr';
import styles from './ThematicsList.module.scss';
-const ThematicsList = () => {
+const ThematicsList = ({ title }: { title: string }) => {
+ const router = useRouter();
+ const isThematic = () => router.asPath.includes('/thematique/');
+ const currentThematicSlug = isThematic()
+ ? router.asPath.replace('/thematique/', '')
+ : '';
+
const { data, error } = useSWR('/api/thematics', getAllThematics);
if (error) return <div>{t`Failed to load.`}</div>;
@@ -16,18 +22,20 @@ const ThematicsList = () => {
);
const thematics = sortedThematics.map((thematic) => {
- return (
+ return currentThematicSlug !== thematic.slug ? (
<li key={thematic.databaseId}>
<Link href={`/thematique/${thematic.slug}`}>
<a>{thematic.title}</a>
</Link>
</li>
+ ) : (
+ ''
);
});
return (
<div>
- <h2 className={styles.title}>{t`Thematics`}</h2>
+ <h2 className={styles.title}>{title}</h2>
<ul className={styles.list}>{thematics}</ul>
</div>
);