diff options
| author | Armand Philippot <git@armandphilippot.com> | 2023-11-24 20:00:08 +0100 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2023-11-27 14:47:51 +0100 |
| commit | f111685c5886f3e77edfd3621c98d8ac1b9bcce4 (patch) | |
| tree | 62a541fe3afeb64bf745443706fbfb02e96c5230 /src/pages/404.tsx | |
| parent | bee515641cb144be9a855ff2cac258d2fedab21d (diff) | |
refactor(services, types): reorganize GraphQL fetchers and data types
The Typescript mapped types was useful for autocompletion in fetchers
but their are harder to maintain. I think it's better to keep each
query close to its fetcher to have a better understanding of the
fetched data. So I:
* colocate queries with their own fetcher
* colocate mutations with their own mutator
* remove Typescript mapped types for queries and mutations
* move data convertors inside graphql services
* rename most of data types and fetchers
Diffstat (limited to 'src/pages/404.tsx')
| -rw-r--r-- | src/pages/404.tsx | 37 |
1 files changed, 16 insertions, 21 deletions
diff --git a/src/pages/404.tsx b/src/pages/404.tsx index d6785b6..5f4f89d 100644 --- a/src/pages/404.tsx +++ b/src/pages/404.tsx @@ -18,25 +18,26 @@ import { type SearchFormSubmit, } from '../components'; import { - getThematicsPreview, - getTopicsPreview, - getTotalThematics, - getTotalTopics, + convertTaxonomyToPageLink, + fetchThematicsCount, + fetchThematicsList, + fetchTopicsCount, + fetchTopicsList, } from '../services/graphql'; import type { NextPageWithLayout, - RawThematicPreview, - RawTopicPreview, + WPThematicPreview, + WPTopicPreview, } from '../types'; import { CONFIG } from '../utils/config'; import { ROUTES } from '../utils/constants'; -import { getLinksItemData, getPageLinkFromRawData } from '../utils/helpers'; +import { getLinksItemData } from '../utils/helpers'; import { loadTranslation, type Messages } from '../utils/helpers/server'; import { useBreadcrumb } from '../utils/hooks'; type Error404PageProps = { - thematicsList: RawThematicPreview[]; - topicsList: RawTopicPreview[]; + thematicsList: WPThematicPreview[]; + topicsList: WPTopicPreview[]; translation: Messages; }; @@ -146,11 +147,7 @@ const Error404Page: NextPageWithLayout<Error404PageProps> = ({ {thematicsListTitle} </Heading> } - items={getLinksItemData( - thematicsList.map((thematic) => - getPageLinkFromRawData(thematic, 'thematic') - ) - )} + items={getLinksItemData(thematicsList.map(convertTaxonomyToPageLink))} /> <LinksWidget heading={ @@ -158,9 +155,7 @@ const Error404Page: NextPageWithLayout<Error404PageProps> = ({ {topicsListTitle} </Heading> } - items={getLinksItemData( - topicsList.map((topic) => getPageLinkFromRawData(topic, 'topic')) - )} + items={getLinksItemData(topicsList.map(convertTaxonomyToPageLink))} /> </PageSidebar> </Page> @@ -172,10 +167,10 @@ Error404Page.getLayout = (page) => getLayout(page); export const getStaticProps: GetStaticProps<Error404PageProps> = async ({ locale, }) => { - const totalThematics = await getTotalThematics(); - const thematics = await getThematicsPreview({ first: totalThematics }); - const totalTopics = await getTotalTopics(); - const topics = await getTopicsPreview({ first: totalTopics }); + const totalThematics = await fetchThematicsCount(); + const thematics = await fetchThematicsList({ first: totalThematics }); + const totalTopics = await fetchTopicsCount(); + const topics = await fetchTopicsList({ first: totalTopics }); const translation = await loadTranslation(locale); return { |
