diff options
| author | Armand Philippot <git@armandphilippot.com> | 2021-12-20 00:15:20 +0100 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2021-12-20 00:15:20 +0100 |
| commit | fa6adedc42e9c6ec39cc30df16b54900c220b094 (patch) | |
| tree | 6bb498beadaa382245cecb86ce56931580313c6f /src/ts/types/articles.ts | |
| parent | 2ff898626c5c0abc6b8195224067b992403e313b (diff) | |
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.
Diffstat (limited to 'src/ts/types/articles.ts')
| -rw-r--r-- | src/ts/types/articles.ts | 90 |
1 files changed, 39 insertions, 51 deletions
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<ACFPosts, 'postsInThematic'>; + contentParts: Pick<ContentParts, 'beforeMore'>; + date: string; + featuredImage: RawCover; + modified: string; + slug: string; }; -export type FetchPostByReturn = (slug: string) => Promise<PostByResponse>; - -export type GetPostByReturn = (slug: string) => Promise<Article>; +export type PostBy = { + postBy: RawArticle; +}; export type ArticleProps = { post: Article; }; - -export type ArticleSlug = { - slug: string; -}; |
