From 67d94ce796e425f1a87806b848f58328ea7adde7 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Tue, 11 Jan 2022 12:56:59 +0100 Subject: chore: add meta, toc and widgets on thematic pages --- src/pages/thematique/[slug].tsx | 50 +++++++++++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 9 deletions(-) (limited to 'src/pages') diff --git a/src/pages/thematique/[slug].tsx b/src/pages/thematique/[slug].tsx index 72e469c..4921806 100644 --- a/src/pages/thematique/[slug].tsx +++ b/src/pages/thematique/[slug].tsx @@ -2,29 +2,57 @@ import { getLayout } from '@components/Layouts/Layout'; import PostPreview from '@components/PostPreview/PostPreview'; import { t } from '@lingui/macro'; import { NextPageWithLayout } from '@ts/types/app'; -import { ThematicProps } from '@ts/types/taxonomies'; +import { SubjectPreview, ThematicProps } from '@ts/types/taxonomies'; import { loadTranslation } from '@utils/helpers/i18n'; import { GetStaticPaths, GetStaticProps, GetStaticPropsContext } from 'next'; import { ParsedUrlQuery } from 'querystring'; -import styles from '@styles/pages/Listing.module.scss'; +import styles from '@styles/pages/Page.module.scss'; import { getAllThematicsSlug, getThematicBySlug, } from '@services/graphql/queries'; import PostHeader from '@components/PostHeader/PostHeader'; +import ToC from '@components/ToC/ToC'; +import { RelatedTopics, ThematicsList } from '@components/Widget'; +import { useRef } from 'react'; +import { ArticleMeta } from '@ts/types/articles'; const Thematic: NextPageWithLayout = ({ thematic }) => { + const relatedSubjects = useRef([]); + + const updateRelatedSubjects = (newSubjects: SubjectPreview[]) => { + newSubjects.forEach((subject) => { + const subjectIndex = relatedSubjects.current.findIndex( + (relatedSubject) => relatedSubject.id === subject.id + ); + const hasSubject = subjectIndex === -1 ? false : true; + + if (!hasSubject) relatedSubjects.current.push(subject); + }); + }; + const getPostsList = () => { - return [...thematic.posts].reverse().map((post) => ( -
  • - -
  • - )); + return [...thematic.posts].reverse().map((post) => { + updateRelatedSubjects(post.subjects); + + return ( +
  • + +
  • + ); + }); + }; + + const meta: ArticleMeta = { + dates: thematic.dates, }; return ( -
    - +
    + +
    {thematic.posts.length > 0 && ( @@ -34,6 +62,10 @@ const Thematic: NextPageWithLayout = ({ thematic }) => { )}
    +
    ); }; -- cgit v1.2.3