From 8bd9784acdee6871ad70e86d0d7120299bf76969 Mon Sep 17 00:00:00 2001
From: Armand Philippot <git@armandphilippot.com>
Date: Tue, 1 Mar 2022 22:05:08 +0100
Subject: refactor: split posts meta into smaller components

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

(limited to 'src/components/MetaItems/Topics/Topics.tsx')

diff --git a/src/components/MetaItems/Topics/Topics.tsx b/src/components/MetaItems/Topics/Topics.tsx
new file mode 100644
index 0000000..4f2dc1f
--- /dev/null
+++ b/src/components/MetaItems/Topics/Topics.tsx
@@ -0,0 +1,36 @@
+import { MetaKind } from '@ts/types/app';
+import { TopicPreview } from '@ts/types/taxonomies';
+import Link from 'next/link';
+import { useIntl } from 'react-intl';
+import { MetaItem } from '..';
+
+const Topics = ({ list, kind }: { list: TopicPreview[]; kind: MetaKind }) => {
+  const intl = useIntl();
+
+  const getTopics = () => {
+    return list.map((topic) => {
+      return (
+        <Link key={topic.databaseId} href={`/sujet/${topic.slug}`}>
+          <a>{topic.title}</a>
+        </Link>
+      );
+    });
+  };
+
+  return (
+    <MetaItem
+      title={intl.formatMessage(
+        {
+          defaultMessage:
+            '{topicsCount, plural, =0 {Topics:} one {Topic:} other {Topics:}}',
+          description: 'Topics: topics list meta label',
+        },
+        { topicsCount: list.length }
+      )}
+      values={getTopics()}
+      kind={kind}
+    />
+  );
+};
+
+export default Topics;
-- 
cgit v1.2.3

