From 04a1ceb257311a98fffc4b18679f73789b920e09 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Mon, 3 Jan 2022 12:24:04 +0100 Subject: chore: display subjects list under articles --- src/utils/helpers/format.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src/utils/helpers/format.ts') diff --git a/src/utils/helpers/format.ts b/src/utils/helpers/format.ts index 81bae9c..94aa2e7 100644 --- a/src/utils/helpers/format.ts +++ b/src/utils/helpers/format.ts @@ -7,8 +7,10 @@ import { import { Comment, RawComment } from '@ts/types/comments'; import { RawSubject, + RawSubjectPreview, RawThematic, Subject, + SubjectPreview, Thematic, } from '@ts/types/taxonomies'; @@ -185,6 +187,19 @@ export const buildCommentsTree = (comments: Comment[]) => { return commentsTree; }; +export const getFormattedSubjectsPreview = ( + subjects: RawSubjectPreview[] +): SubjectPreview[] => { + const formattedSubjects: SubjectPreview[] = subjects.map((subject) => { + return { + ...subject, + featuredImage: subject.featuredImage ? subject.featuredImage.node : null, + }; + }); + + return formattedSubjects; +}; + /** * Format an article from RawArticle to Article type. * @param rawPost - An article coming from WP GraphQL. @@ -212,6 +227,9 @@ export const getFormattedPost = (rawPost: RawArticle): Article => { const formattedComments = getFormattedComments(comments.nodes); const commentsTree = buildCommentsTree(formattedComments); + const subjects = acfPosts.postsInSubject + ? getFormattedSubjectsPreview(acfPosts.postsInSubject) + : []; const formattedPost: Article = { author: author.node, @@ -223,7 +241,7 @@ export const getFormattedPost = (rawPost: RawArticle): Article => { id, intro: contentParts.beforeMore, seo, - subjects: acfPosts.postsInSubject ? acfPosts.postsInSubject : [], + subjects, thematics: acfPosts.postsInThematic ? acfPosts.postsInThematic : [], title, }; -- cgit v1.2.3