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/taxonomies.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/taxonomies.ts')
| -rw-r--r-- | src/ts/types/taxonomies.ts | 114 |
1 files changed, 54 insertions, 60 deletions
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<Taxonomy, 'databaseId' | 'id' | 'title'> & { + 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<ThematicByResponse>; +export type Thematic = Taxonomy; -export type GetTaxonomyByReturn = (slug: string) => Promise<Taxonomy>; - -export type FetchAllTaxonomiesSlugReturn = () => Promise<AllTaxonomiesSlug[]>; - -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<SubjectByResponse>; +export type SubjectProps = { + subject: Subject; +}; -export type AllSubjectsSlugResponse = { - subjects: { - nodes: AllTaxonomiesSlug[]; - }; +export type ThematicProps = { + thematic: Thematic; }; |
