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/app.ts | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) (limited to 'src/ts/types/app.ts') diff --git a/src/ts/types/app.ts b/src/ts/types/app.ts index 488fe6e..ba28416 100644 --- a/src/ts/types/app.ts +++ b/src/ts/types/app.ts @@ -1,6 +1,22 @@ import { NextPage } from 'next'; import { AppProps } from 'next/app'; import { ReactElement, ReactNode } from 'react'; +import { PostBy } from './articles'; +import { AllPostsSlug, RawPostsList } from './blog'; +import { CommentData, CreateComment } from './comments'; +import { ContactData, SendEmail } from './contact'; +import { HomePageBy } from './homepage'; +import { PageBy } from './pages'; +import { + AllSubjectsSlug, + AllThematicsSlug, + SubjectBy, + ThematicBy, +} from './taxonomies'; + +//============================================================================== +// Next +//============================================================================== export type NextPageWithLayout

= NextPage

& { getLayout?: (page: ReactElement) => ReactNode; @@ -9,3 +25,62 @@ export type NextPageWithLayout

= NextPage

& { export type AppPropsWithLayout = AppProps & { Component: NextPageWithLayout; }; + +//============================================================================== +// API +//============================================================================== + +export type VariablesType = T extends + | PageBy + | PostBy + | SubjectBy + | ThematicBy + ? Slug + : T extends RawPostsList + ? CursorPagination + : T extends CreateComment + ? CommentData + : T extends SendEmail + ? ContactData + : null; + +export type RequestType = + | AllPostsSlug + | AllSubjectsSlug + | AllThematicsSlug + | CreateComment + | HomePageBy + | PageBy + | PostBy + | SubjectBy + | ThematicBy + | RawPostsList + | SendEmail; + +//============================================================================== +// Globals +//============================================================================== + +export type ContentParts = { + afterMore: string; + beforeMore: string; +}; + +export type CursorPagination = { + first: number; + after: string; +}; + +export type Dates = { + publication: string; + update: string; +}; + +export type PageInfo = { + endCursor: string; + hasNextPage: boolean; +}; + +export type Slug = { + slug: string; +}; -- cgit v1.2.3