From b4e12398fbeb642c12649dcccdf4d5cdefa471e3 Mon Sep 17 00:00:00 2001
From: Armand Philippot <git@armandphilippot.com>
Date: Fri, 7 Jan 2022 12:01:08 +0100
Subject: chore: add a widget to list all blog thematics

---
 .../Widget/ThematicsList/ThematicsList.tsx         | 36 ++++++++++++++++++++++
 1 file changed, 36 insertions(+)
 create mode 100644 src/components/Widget/ThematicsList/ThematicsList.tsx

(limited to 'src/components/Widget/ThematicsList/ThematicsList.tsx')

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;
-- 
cgit v1.2.3

