diff options
| author | Armand Philippot <git@armandphilippot.com> | 2022-01-11 12:54:24 +0100 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2022-01-11 15:33:04 +0100 |
| commit | 812a8fad8cd703d3e501d03b280b8e5749f4ae57 (patch) | |
| tree | c07f8dfe20721e757f8cd21dd955a42b9c564276 /src | |
| parent | 9b8eced56f5e029bc92ad59b47cb9fd146b5e1d2 (diff) | |
chore(widget): add a related topics widget
Diffstat (limited to 'src')
| -rw-r--r-- | src/components/Widget/RelatedTopics/RelatedTopics.tsx | 29 | ||||
| -rw-r--r-- | src/components/Widget/ThematicsList/ThematicsList.tsx | 2 | ||||
| -rw-r--r-- | src/components/Widget/TopicsList/TopicsList.module.scss | 7 | ||||
| -rw-r--r-- | src/components/Widget/TopicsList/TopicsList.tsx | 2 | ||||
| -rw-r--r-- | src/components/Widget/Widget.module.scss (renamed from src/components/Widget/ThematicsList/ThematicsList.module.scss) | 0 | ||||
| -rw-r--r-- | src/components/Widget/index.tsx | 2 |
6 files changed, 33 insertions, 9 deletions
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; diff --git a/src/components/Widget/ThematicsList/ThematicsList.tsx b/src/components/Widget/ThematicsList/ThematicsList.tsx index 0dc0916..f120978 100644 --- a/src/components/Widget/ThematicsList/ThematicsList.tsx +++ b/src/components/Widget/ThematicsList/ThematicsList.tsx @@ -3,7 +3,7 @@ import { getAllThematics } from '@services/graphql/queries'; import Link from 'next/link'; import { useRouter } from 'next/router'; import useSWR from 'swr'; -import styles from './ThematicsList.module.scss'; +import styles from '../Widget.module.scss'; const ThematicsList = ({ title }: { title: string }) => { const router = useRouter(); diff --git a/src/components/Widget/TopicsList/TopicsList.module.scss b/src/components/Widget/TopicsList/TopicsList.module.scss deleted file mode 100644 index 5f37c7a..0000000 --- a/src/components/Widget/TopicsList/TopicsList.module.scss +++ /dev/null @@ -1,7 +0,0 @@ -.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 index fabd40d..179d129 100644 --- a/src/components/Widget/TopicsList/TopicsList.tsx +++ b/src/components/Widget/TopicsList/TopicsList.tsx @@ -2,7 +2,7 @@ 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'; +import styles from '../Widget.module.scss'; const TopicsList = () => { const { data, error } = useSWR('/api/subjects', getAllSubjects); diff --git a/src/components/Widget/ThematicsList/ThematicsList.module.scss b/src/components/Widget/Widget.module.scss index 5f37c7a..5f37c7a 100644 --- a/src/components/Widget/ThematicsList/ThematicsList.module.scss +++ b/src/components/Widget/Widget.module.scss diff --git a/src/components/Widget/index.tsx b/src/components/Widget/index.tsx index 9a9aea8..a90fdca 100644 --- a/src/components/Widget/index.tsx +++ b/src/components/Widget/index.tsx @@ -1,5 +1,6 @@ import CVPreview from './CVPreview/CVPreview'; import RecentPosts from './RecentPosts/RecentPosts'; +import RelatedTopics from './RelatedTopics/RelatedTopics'; import Sharing from './Sharing/Sharing'; import SocialMedia from './SocialMedia/SocialMedia'; import ThematicsList from './ThematicsList/ThematicsList'; @@ -8,6 +9,7 @@ import TopicsList from './TopicsList/TopicsList'; export { CVPreview, RecentPosts, + RelatedTopics, Sharing, SocialMedia, ThematicsList, |
