From 98dd62e28793bad9c121a9f16b11a10222a41c50 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Tue, 11 Jan 2022 11:41:58 +0100 Subject: 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. --- src/components/Widget/ThematicsList/ThematicsList.tsx | 16 ++++++++++++---- src/pages/blog/index.tsx | 2 +- 2 files changed, 13 insertions(+), 5 deletions(-) (limited to 'src') 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
{t`Failed to load.`}
; @@ -16,18 +22,20 @@ const ThematicsList = () => { ); const thematics = sortedThematics.map((thematic) => { - return ( + return currentThematicSlug !== thematic.slug ? (
  • {thematic.title}
  • + ) : ( + '' ); }); return (
    -

    {t`Thematics`}

    +

    {title}

    ); diff --git a/src/pages/blog/index.tsx b/src/pages/blog/index.tsx index 1bd6c62..0804cd2 100644 --- a/src/pages/blog/index.tsx +++ b/src/pages/blog/index.tsx @@ -61,7 +61,7 @@ const Blog: NextPageWithLayout = ({ fallback }) => { >{t`Load more?`} )} - + -- cgit v1.2.3