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 (
{intl.formatMessage({
defaultMessage: 'Failed to load.',
description: 'ThematicsList: failed to load text',
})}
);
if (!data)
return (
);
const thematics = data.map((thematic) => {
return currentThematicSlug !== thematic.slug ? (
{thematic.title}
) : (
''
);
});
return
;
};
return (
{getList()}
);
};
export default ThematicsList;
href='/www.armandphilippot.com/diff/public/prism/prism-web-idl.js?id=3ed7f185e82c0cc87c63b75dc8cddfecc5c608ce'>diffstats
|
blob: 48c97c0bd9d014f5deaf0b536719845bc3f12ebb (
plain)