From fa6adedc42e9c6ec39cc30df16b54900c220b094 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Mon, 20 Dec 2021 00:15:20 +0100 Subject: refactor: rewrite types and services I was repeating myself a lot in services. So I rewrited the different functions to improve readability and I extracted some formatting functions to put them in utils. I also rewrited/reorganized some types to keep consistent names. --- src/ts/types/articles.ts | 90 +++++++++++++++++++++--------------------------- 1 file changed, 39 insertions(+), 51 deletions(-) (limited to 'src/ts/types/articles.ts') diff --git a/src/ts/types/articles.ts b/src/ts/types/articles.ts index afaa3e3..e6a40ef 100644 --- a/src/ts/types/articles.ts +++ b/src/ts/types/articles.ts @@ -1,80 +1,68 @@ -import { Comment, CommentsResponse } from './comments'; -import { Cover, CoverResponse } from './cover'; +import { ContentParts, Dates } from './app'; +import { Comment, CommentsNode } from './comments'; +import { Cover, RawCover } from './cover'; import { SEO } from './seo'; import { SubjectPreview, ThematicPreview } from './taxonomies'; -export type ArticleDates = { - publication: string; - update: string; -}; - export type ArticleAuthor = { firstName: string; lastName: string; name: string; }; -export type ArticlePreviewResponse = { - acfPosts: { - postsInSubject: SubjectPreview[] | null; - postsInThematic: ThematicPreview[] | null; - }; - commentCount: number | null; - contentParts: { - beforeMore: string; - }; - databaseId: number; - date: string; - featuredImage: CoverResponse; - id: string; - modified: string; - slug: string; - title: string; +export type ACFPosts = { + postsInSubject: SubjectPreview[] | null; + postsInThematic: ThematicPreview[] | null; }; -export type ArticlePreview = { +export type Article = { + author: ArticleAuthor; commentCount: number | null; + comments: Comment[]; content: string; databaseId: number; - date: ArticleDates; - featuredImage: Cover | null; + dates: Dates; id: string; - slug: string; + intro: string; + seo: SEO; subjects: SubjectPreview[] | []; thematics: ThematicPreview[] | []; title: string; }; -export type ArticleResponse = ArticlePreviewResponse & { - author: { - node: ArticleAuthor; - }; - comments: CommentsResponse; - contentParts: { - afterMore: string; - }; - seo: SEO; +export type RawArticle = Pick< + Article, + 'commentCount' | 'databaseId' | 'id' | 'seo' | 'title' +> & { + acfPosts: ACFPosts; + author: { node: ArticleAuthor }; + comments: CommentsNode; + contentParts: ContentParts; + date: string; + modified: string; }; -export type Article = ArticlePreview & { - author: ArticleAuthor; - comments: Comment[]; - intro: string; - seo: SEO; -}; +export type ArticlePreview = Pick< + Article, + 'commentCount' | 'dates' | 'id' | 'intro' | 'thematics' | 'title' +> & { featuredImage: Cover; slug: string }; -export type PostByResponse = { - postBy: ArticleResponse; +export type RawArticlePreview = Pick< + Article, + 'commentCount' | 'id' | 'title' +> & { + acfPosts: Pick; + contentParts: Pick; + date: string; + featuredImage: RawCover; + modified: string; + slug: string; }; -export type FetchPostByReturn = (slug: string) => Promise; - -export type GetPostByReturn = (slug: string) => Promise
; +export type PostBy = { + postBy: RawArticle; +}; export type ArticleProps = { post: Article; }; - -export type ArticleSlug = { - slug: string; -}; -- cgit v1.2.3