diff options
| author | Armand Philippot <git@armandphilippot.com> | 2022-01-07 12:01:08 +0100 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2022-01-07 12:31:56 +0100 |
| commit | b4e12398fbeb642c12649dcccdf4d5cdefa471e3 (patch) | |
| tree | 0744b64eed4214813e70ed26ad4a18058a4a46af /src/components/Widget/ThematicsList/ThematicsList.tsx | |
| parent | 722ec20bad64d8c69b173c163011d37ad0b55591 (diff) | |
chore: add a widget to list all blog thematics
Diffstat (limited to 'src/components/Widget/ThematicsList/ThematicsList.tsx')
| -rw-r--r-- | src/components/Widget/ThematicsList/ThematicsList.tsx | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/components/Widget/ThematicsList/ThematicsList.tsx b/src/components/Widget/ThematicsList/ThematicsList.tsx new file mode 100644 index 0000000..232515d --- /dev/null +++ b/src/components/Widget/ThematicsList/ThematicsList.tsx @@ -0,0 +1,36 @@ +import { t } from '@lingui/macro'; +import { getAllThematics } from '@services/graphql/queries'; +import { ThematicPreview } from '@ts/types/taxonomies'; +import Link from 'next/link'; +import useSWR from 'swr'; +import styles from './ThematicsList.module.scss'; + +const ThematicsList = () => { + const { data, error } = useSWR('/api/thematics', getAllThematics); + + if (error) return <div>{t`Failed to load.`}</div>; + if (!data) return <div>{t`Loading...`}</div>; + + const sortedThematics = [...data].sort((a, b) => + a.title.localeCompare(b.title) + ); + + const thematics = sortedThematics.map((thematic) => { + return ( + <li key={thematic.databaseId}> + <Link href={`/thematique/${thematic.slug}`}> + <a>{thematic.title}</a> + </Link> + </li> + ); + }); + + return ( + <div> + <h2 className={styles.title}>{t`Thematics`}</h2> + <ul className={styles.list}>{thematics}</ul> + </div> + ); +}; + +export default ThematicsList; |
