diff options
| author | Armand Philippot <git@armandphilippot.com> | 2022-01-11 12:56:59 +0100 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2022-01-11 15:33:04 +0100 |
| commit | 67d94ce796e425f1a87806b848f58328ea7adde7 (patch) | |
| tree | 030400abbd959909be51756367b7bb20035d1d72 /src/pages | |
| parent | 812a8fad8cd703d3e501d03b280b8e5749f4ae57 (diff) | |
chore: add meta, toc and widgets on thematic pages
Diffstat (limited to 'src/pages')
| -rw-r--r-- | src/pages/thematique/[slug].tsx | 50 |
1 files changed, 41 insertions, 9 deletions
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<ThematicProps> = ({ thematic }) => { + const relatedSubjects = useRef<SubjectPreview[]>([]); + + 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) => ( - <li key={post.id} className={styles.item}> - <PostPreview post={post} titleLevel={3} /> - </li> - )); + return [...thematic.posts].reverse().map((post) => { + updateRelatedSubjects(post.subjects); + + return ( + <li key={post.id} className={styles.item}> + <PostPreview post={post} titleLevel={3} /> + </li> + ); + }); + }; + + const meta: ArticleMeta = { + dates: thematic.dates, }; return ( - <article className={styles.wrapper}> - <PostHeader intro={thematic.intro} title={thematic.title} /> + <article className={`${styles.article} ${styles['article--no-comments']}`}> + <PostHeader intro={thematic.intro} meta={meta} title={thematic.title} /> + <aside className={styles.toc}> + <ToC /> + </aside> <div className={styles.body}> <div dangerouslySetInnerHTML={{ __html: thematic.content }}></div> {thematic.posts.length > 0 && ( @@ -34,6 +62,10 @@ const Thematic: NextPageWithLayout<ThematicProps> = ({ thematic }) => { </section> )} </div> + <aside className={`${styles.aside} ${styles['aside--overflow']}`}> + <RelatedTopics topics={relatedSubjects.current} /> + <ThematicsList title={t`Other thematics`} /> + </aside> </article> ); }; |
