From b405ddb76f217ccf7828b422ec4c0f0e15b7dee4 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Fri, 7 Jan 2022 12:33:35 +0100 Subject: chore: add a widget to list all blog topics --- .../Widget/TopicsList/TopicsList.module.scss | 7 +++++ src/components/Widget/TopicsList/TopicsList.tsx | 35 ++++++++++++++++++++++ src/components/Widget/index.tsx | 3 +- 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 src/components/Widget/TopicsList/TopicsList.module.scss create mode 100644 src/components/Widget/TopicsList/TopicsList.tsx (limited to 'src/components/Widget') diff --git a/src/components/Widget/TopicsList/TopicsList.module.scss b/src/components/Widget/TopicsList/TopicsList.module.scss new file mode 100644 index 0000000..5f37c7a --- /dev/null +++ b/src/components/Widget/TopicsList/TopicsList.module.scss @@ -0,0 +1,7 @@ +.title { + margin: 0; +} + +.list { + margin: var(--spacing-sm) 0; +} diff --git a/src/components/Widget/TopicsList/TopicsList.tsx b/src/components/Widget/TopicsList/TopicsList.tsx new file mode 100644 index 0000000..fabd40d --- /dev/null +++ b/src/components/Widget/TopicsList/TopicsList.tsx @@ -0,0 +1,35 @@ +import { t } from '@lingui/macro'; +import { getAllSubjects } from '@services/graphql/queries'; +import Link from 'next/link'; +import useSWR from 'swr'; +import styles from './TopicsList.module.scss'; + +const TopicsList = () => { + const { data, error } = useSWR('/api/subjects', getAllSubjects); + + if (error) return
{t`Failed to load.`}
; + if (!data) return
{t`Loading...`}
; + + const sortedSubjects = [...data].sort((a, b) => + a.title.localeCompare(b.title) + ); + + const subjects = sortedSubjects.map((subject) => { + return ( +
  • + + {subject.title} + +
  • + ); + }); + + return ( +
    +

    {t`Topics`}

    + +
    + ); +}; + +export default TopicsList; diff --git a/src/components/Widget/index.tsx b/src/components/Widget/index.tsx index 025b302..e4e346f 100644 --- a/src/components/Widget/index.tsx +++ b/src/components/Widget/index.tsx @@ -1,4 +1,5 @@ import RecentPosts from './RecentPosts/RecentPosts'; import ThematicsList from './ThematicsList/ThematicsList'; +import TopicsList from './TopicsList/TopicsList'; -export { RecentPosts, ThematicsList }; +export { RecentPosts, ThematicsList, TopicsList }; -- cgit v1.2.3