diff options
Diffstat (limited to 'src/components/Widget/ThematicsList')
| -rw-r--r-- | src/components/Widget/ThematicsList/ThematicsList.tsx | 16 | 
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>    ); | 
