import Spinner from '@components/Spinner/Spinner'; import { ExpandableWidget, List } from '@components/WidgetParts'; import { getAllThematics } from '@services/graphql/queries'; import { TitleLevel } from '@ts/types/app'; import { ThematicPreview } from '@ts/types/taxonomies'; import Link from 'next/link'; import { useRouter } from 'next/router'; import { useIntl } from 'react-intl'; import useSWR from 'swr'; const ThematicsList = ({ title, titleLevel, initialData, }: { title: string; titleLevel?: TitleLevel; initialData?: ThematicPreview[]; }) => { const intl = useIntl(); const router = useRouter(); const isThematic = () => router.asPath.includes('/thematique/'); const currentThematicSlug = isThematic() ? router.asPath.replace('/thematique/', '') : ''; const { data, error } = useSWR('/api/thematics', getAllThematics, { fallbackData: initialData, }); const getList = () => { if (error) return ( ); if (!data) return ( ); const thematics = data.map((thematic) => { return currentThematicSlug !== thematic.slug ? (
  • {thematic.title}
  • ) : ( '' ); }); return ; }; return ( {getList()} ); }; export default ThematicsList;