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/taxonomies.ts | 114 +++++++++++++++++++++------------------------ 1 file changed, 54 insertions(+), 60 deletions(-) (limited to 'src/ts/types/taxonomies.ts') diff --git a/src/ts/types/taxonomies.ts b/src/ts/types/taxonomies.ts index a8c372c..3945934 100644 --- a/src/ts/types/taxonomies.ts +++ b/src/ts/types/taxonomies.ts @@ -1,96 +1,90 @@ -import { ArticlePreview, ArticlePreviewResponse } from './articles'; -import { Cover, CoverResponse } from './cover'; +import { ContentParts, Dates, Slug } from './app'; +import { ArticlePreview, RawArticlePreview } from './articles'; +import { Cover, RawCover } from './cover'; -type TaxonomyPreview = { +//============================================================================== +// Taxonomies base +//============================================================================== + +type Taxonomy = { + content: string; databaseId: number; + dates: Dates; id: string; - slug: string; + intro: string; + posts: ArticlePreview[]; title: string; }; -export type Taxonomy = TaxonomyPreview & { - content: string; - date: string; - intro: string; - modified: string; - posts: ArticlePreview[]; +type TaxonomyPreview = Pick & { + slug: string; }; -export type SubjectPreview = TaxonomyPreview & { +//============================================================================== +// Subjects +//============================================================================== + +export type Subject = Taxonomy & { featuredImage: Cover; + officialWebsite: string; }; -export type ThematicPreview = TaxonomyPreview; +export type SubjectPreview = TaxonomyPreview & { + featuredImage: Cover; +}; -export type ThematicResponse = TaxonomyPreview & { - acfThematics: { - postsInThematic: ArticlePreviewResponse[]; - }; - contentParts: { - afterMore: string; - beforeMore: string; +export type RawSubject = SubjectPreview & { + acfSubjects: { + officialWebsite: string; + postsInSubject: RawArticlePreview[]; }; + contentParts: ContentParts; date: string; + featuredImage: RawCover; modified: string; }; -export type ThematicProps = { - thematic: Taxonomy; -}; - -export type AllTaxonomiesSlug = { - slug: string; +export type SubjectBy = { + subjectBy: RawSubject; }; -export type AllThematicsSlugResponse = { - thematics: { - nodes: AllTaxonomiesSlug[]; +export type AllSubjectsSlug = { + subjects: { + nodes: Slug[]; }; }; -export type ThematicByResponse = { - thematicBy: ThematicResponse; -}; +//============================================================================== +// Thematics +//============================================================================== -export type FetchThematicByReturn = ( - slug: string -) => Promise; +export type Thematic = Taxonomy; -export type GetTaxonomyByReturn = (slug: string) => Promise; - -export type FetchAllTaxonomiesSlugReturn = () => Promise; - -export type Subject = Taxonomy & { - featuredImage: Cover; - officialWebsite: string; -}; +export type ThematicPreview = TaxonomyPreview; -export type SubjectResponse = SubjectPreview & { - acfSubjects: { - postsInSubject: ArticlePreviewResponse[]; - }; - contentParts: { - afterMore: string; - beforeMore: string; +export type RawThematic = TaxonomyPreview & { + acfThematics: { + postsInThematic: RawArticlePreview[]; }; + contentParts: ContentParts; date: string; - featuredImage: CoverResponse; modified: string; - officialWebsite: string; }; -export type SubjectProps = { - subject: Subject; +export type ThematicBy = { + thematicBy: RawThematic; }; -export type SubjectByResponse = { - subjectBy: SubjectResponse; +export type AllThematicsSlug = { + thematics: { + nodes: Slug[]; + }; }; -export type FetchSubjectByReturn = (slug: string) => Promise; +export type SubjectProps = { + subject: Subject; +}; -export type AllSubjectsSlugResponse = { - subjects: { - nodes: AllTaxonomiesSlug[]; - }; +export type ThematicProps = { + thematic: Thematic; }; -- cgit v1.2.3