From 3d35170404b280bb70913ef41b0478ca65e00d72 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Tue, 11 Jan 2022 13:04:50 +0100 Subject: 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. --- src/components/Widget/TopicsList/TopicsList.tsx | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/components') 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
{t`Failed to load.`}
; @@ -15,18 +22,20 @@ const TopicsList = () => { ); const subjects = sortedSubjects.map((subject) => { - return ( + return currentTopicSlug !== subject.slug ? (
  • {subject.title}
  • + ) : ( + '' ); }); return (
    -

    {t`Topics`}

    +

    {title}

    ); -- cgit v1.2.3