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 | |
| parent | 722ec20bad64d8c69b173c163011d37ad0b55591 (diff) | |
chore: add a widget to list all blog thematics
Diffstat (limited to 'src/components/Widget')
| -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 }; | 
