diff options
Diffstat (limited to 'src/components')
| -rw-r--r-- | src/components/Widget/ThematicsList/ThematicsList.module.scss | 7 | ||||
| -rw-r--r-- | src/components/Widget/ThematicsList/ThematicsList.tsx | 36 | ||||
| -rw-r--r-- | src/components/Widget/index.tsx | 3 |
3 files changed, 45 insertions, 1 deletions
diff --git a/src/components/Widget/ThematicsList/ThematicsList.module.scss b/src/components/Widget/ThematicsList/ThematicsList.module.scss new file mode 100644 index 0000000..5f37c7a --- /dev/null +++ b/src/components/Widget/ThematicsList/ThematicsList.module.scss @@ -0,0 +1,7 @@ +.title { + margin: 0; +} + +.list { + margin: var(--spacing-sm) 0; +} 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; diff --git a/src/components/Widget/index.tsx b/src/components/Widget/index.tsx index d6ce18f..025b302 100644 --- a/src/components/Widget/index.tsx +++ b/src/components/Widget/index.tsx @@ -1,3 +1,4 @@ import RecentPosts from './RecentPosts/RecentPosts'; +import ThematicsList from './ThematicsList/ThematicsList'; -export { RecentPosts }; +export { RecentPosts, ThematicsList }; |
