From 812a8fad8cd703d3e501d03b280b8e5749f4ae57 Mon Sep 17 00:00:00 2001
From: Armand Philippot <git@armandphilippot.com>
Date: Tue, 11 Jan 2022 12:54:24 +0100
Subject: chore(widget): add a related topics widget

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

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

diff --git a/src/components/Widget/RelatedTopics/RelatedTopics.tsx b/src/components/Widget/RelatedTopics/RelatedTopics.tsx
new file mode 100644
index 0000000..ad8f5ef
--- /dev/null
+++ b/src/components/Widget/RelatedTopics/RelatedTopics.tsx
@@ -0,0 +1,29 @@
+import { t } from '@lingui/macro';
+import { SubjectPreview } from '@ts/types/taxonomies';
+import Link from 'next/link';
+import styles from '../Widget.module.scss';
+
+const RelatedTopics = ({ topics }: { topics: SubjectPreview[] }) => {
+  const sortedSubjects = [...topics].sort((a, b) =>
+    a.title.localeCompare(b.title)
+  );
+
+  const subjects = sortedSubjects.map((subject) => {
+    return (
+      <li key={subject.databaseId}>
+        <Link href={`/sujet/${subject.slug}`}>
+          <a>{subject.title}</a>
+        </Link>
+      </li>
+    );
+  });
+
+  return (
+    <div>
+      <h2 className={styles.title}>{t`Related topics`}</h2>
+      <ul className={styles.list}>{subjects}</ul>
+    </div>
+  );
+};
+
+export default RelatedTopics;
-- 
cgit v1.2.3

