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/pages | |
| 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/pages')
| -rw-r--r-- | src/pages/article/[slug].tsx | 9 | ||||
| -rw-r--r-- | src/pages/blog/index.tsx | 2 | ||||
| -rw-r--r-- | src/pages/contact.tsx | 10 | ||||
| -rw-r--r-- | src/pages/cv.tsx | 4 | ||||
| -rw-r--r-- | src/pages/index.tsx | 2 | ||||
| -rw-r--r-- | src/pages/mentions-legales.tsx | 4 | ||||
| -rw-r--r-- | src/pages/sujet/[slug].tsx | 11 | ||||
| -rw-r--r-- | src/pages/thematique/[slug].tsx | 10 |
8 files changed, 28 insertions, 24 deletions
diff --git a/src/pages/article/[slug].tsx b/src/pages/article/[slug].tsx index 55753c3..bb11220 100644 --- a/src/pages/article/[slug].tsx +++ b/src/pages/article/[slug].tsx @@ -4,8 +4,7 @@ import Layout from '@components/Layouts/Layout'; import PostFooter from '@components/PostFooter/PostFooter'; import PostHeader from '@components/PostHeader/PostHeader'; import { t } from '@lingui/macro'; -import { fetchAllPostsSlug } from '@services/graphql/blog'; -import { getPostBySlug } from '@services/graphql/post'; +import { getAllPostsSlug, getPostBySlug } from '@services/graphql/queries'; import { NextPageWithLayout } from '@ts/types/app'; import { ArticleProps } from '@ts/types/articles'; import { loadTranslation } from '@utils/helpers/i18n'; @@ -19,7 +18,7 @@ const SingleArticle: NextPageWithLayout<ArticleProps> = ({ post }) => { author, comments, content, - date, + dates, intro, seo, subjects, @@ -36,7 +35,7 @@ const SingleArticle: NextPageWithLayout<ArticleProps> = ({ post }) => { <article> <PostHeader author={author} - date={date} + dates={dates} intro={intro} title={title} thematics={thematics} @@ -81,7 +80,7 @@ export const getStaticProps: GetStaticProps = async ( }; export const getStaticPaths: GetStaticPaths = async () => { - const allSlugs = await fetchAllPostsSlug(); + const allSlugs = await getAllPostsSlug(); return { paths: allSlugs.map((post) => `/article/${post.slug}`), diff --git a/src/pages/blog/index.tsx b/src/pages/blog/index.tsx index 29e7770..7d34763 100644 --- a/src/pages/blog/index.tsx +++ b/src/pages/blog/index.tsx @@ -5,13 +5,13 @@ import { t } from '@lingui/macro'; import Layout from '@components/Layouts/Layout'; import { seo } from '@config/seo'; import { config } from '@config/website'; -import { getPublishedPosts } from '@services/graphql/blog'; import { NextPageWithLayout } from '@ts/types/app'; import { BlogPageProps, PostsList as PostsListData } from '@ts/types/blog'; import { loadTranslation } from '@utils/helpers/i18n'; import PostsList from '@components/PostsList/PostsList'; import useSWRInfinite from 'swr/infinite'; import { Button } from '@components/Buttons'; +import { getPublishedPosts } from '@services/graphql/queries'; const Blog: NextPageWithLayout<BlogPageProps> = ({ fallback }) => { const getKey = (pageIndex: number, previousData: PostsListData) => { diff --git a/src/pages/contact.tsx b/src/pages/contact.tsx index bfdd681..ff60188 100644 --- a/src/pages/contact.tsx +++ b/src/pages/contact.tsx @@ -3,7 +3,7 @@ import { Form, FormItem, Input, TextArea } from '@components/Form'; import Layout from '@components/Layouts/Layout'; import { seo } from '@config/seo'; import { t } from '@lingui/macro'; -import { sendMail } from '@services/graphql/contact'; +import { sendMail } from '@services/graphql/mutations'; import { NextPageWithLayout } from '@ts/types/app'; import { loadTranslation } from '@utils/helpers/i18n'; import { GetStaticProps, GetStaticPropsContext } from 'next'; @@ -28,7 +28,13 @@ const ContactPage: NextPageWithLayout = () => { e.preventDefault(); const body = `Message received from ${name} <${email}> on ArmandPhilippot.com.\n\n${message}`; const replyTo = `${name} <${email}>`; - const mail = await sendMail(subject, body, replyTo, 'contact'); + const data = { + body, + mutationId: 'contact', + replyTo, + subject, + }; + const mail = await sendMail(data); if (mail.sent) { setStatus( diff --git a/src/pages/cv.tsx b/src/pages/cv.tsx index 5b913f3..150e29a 100644 --- a/src/pages/cv.tsx +++ b/src/pages/cv.tsx @@ -1,6 +1,6 @@ import Layout from '@components/Layouts/Layout'; import { seo } from '@config/seo'; -import { getCVPage } from '@services/graphql/pages'; +import { getPageByUri } from '@services/graphql/queries'; import { NextPageWithLayout } from '@ts/types/app'; import { PageProps } from '@ts/types/pages'; import { loadTranslation } from '@utils/helpers/i18n'; @@ -35,7 +35,7 @@ export const getStaticProps: GetStaticProps = async ( context.locale!, process.env.NODE_ENV === 'production' ); - const page = await getCVPage(); + const page = await getPageByUri('/cv/'); return { props: { diff --git a/src/pages/index.tsx b/src/pages/index.tsx index f51dec9..4146f34 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -3,10 +3,10 @@ import { GetStaticProps } from 'next'; import Head from 'next/head'; import Layout from '@components/Layouts/Layout'; import { seo } from '@config/seo'; -import { getHomePage } from '@services/graphql/homepage'; import { NextPageWithLayout } from '@ts/types/app'; import { HomePage, HomePageProps } from '@ts/types/homepage'; import { loadTranslation } from '@utils/helpers/i18n'; +import { getHomePage } from '@services/graphql/queries'; const Home: NextPageWithLayout<HomePageProps> = ({ data }) => { return ( diff --git a/src/pages/mentions-legales.tsx b/src/pages/mentions-legales.tsx index 4ff4104..c90b8d6 100644 --- a/src/pages/mentions-legales.tsx +++ b/src/pages/mentions-legales.tsx @@ -1,6 +1,6 @@ import Layout from '@components/Layouts/Layout'; import { seo } from '@config/seo'; -import { getLegalNoticePage } from '@services/graphql/pages'; +import { getPageByUri } from '@services/graphql/queries'; import { NextPageWithLayout } from '@ts/types/app'; import { PageProps } from '@ts/types/pages'; import { loadTranslation } from '@utils/helpers/i18n'; @@ -35,7 +35,7 @@ export const getStaticProps: GetStaticProps = async ( context.locale!, process.env.NODE_ENV === 'production' ); - const page = await getLegalNoticePage(); + const page = await getPageByUri('/mentions-legales/'); return { props: { diff --git a/src/pages/sujet/[slug].tsx b/src/pages/sujet/[slug].tsx index a6acf2b..4dc4e9b 100644 --- a/src/pages/sujet/[slug].tsx +++ b/src/pages/sujet/[slug].tsx @@ -1,10 +1,6 @@ import Layout from '@components/Layouts/Layout'; import PostPreview from '@components/PostPreview/PostPreview'; import { t } from '@lingui/macro'; -import { - fetchAllSubjectsSlug, - getSubjectBySlug, -} from '@services/graphql/taxonomies'; import { NextPageWithLayout } from '@ts/types/app'; import { SubjectProps } from '@ts/types/taxonomies'; import { loadTranslation } from '@utils/helpers/i18n'; @@ -13,6 +9,10 @@ import Image from 'next/image'; import { ParsedUrlQuery } from 'querystring'; import { ReactElement } from 'react'; import styles from '@styles/pages/Subject.module.scss'; +import { + getAllSubjectsSlug, + getSubjectBySlug, +} from '@services/graphql/queries'; const Subject: NextPageWithLayout<SubjectProps> = ({ subject }) => { const getPostsList = () => { @@ -68,7 +68,6 @@ interface PostParams extends ParsedUrlQuery { export const getStaticProps: GetStaticProps = async ( context: GetStaticPropsContext ) => { - console.log(context); const translation = await loadTranslation( context.locale!, process.env.NODE_ENV === 'production' @@ -85,7 +84,7 @@ export const getStaticProps: GetStaticProps = async ( }; export const getStaticPaths: GetStaticPaths = async () => { - const allSlugs = await fetchAllSubjectsSlug(); + const allSlugs = await getAllSubjectsSlug(); return { paths: allSlugs.map((post) => `/sujet/${post.slug}`), diff --git a/src/pages/thematique/[slug].tsx b/src/pages/thematique/[slug].tsx index 1919b59..2e7c346 100644 --- a/src/pages/thematique/[slug].tsx +++ b/src/pages/thematique/[slug].tsx @@ -1,10 +1,6 @@ import Layout from '@components/Layouts/Layout'; import PostPreview from '@components/PostPreview/PostPreview'; import { t } from '@lingui/macro'; -import { - fetchAllThematicsSlug, - getThematicBySlug, -} from '@services/graphql/taxonomies'; import { NextPageWithLayout } from '@ts/types/app'; import { ThematicProps } from '@ts/types/taxonomies'; import { loadTranslation } from '@utils/helpers/i18n'; @@ -12,6 +8,10 @@ import { GetStaticPaths, GetStaticProps, GetStaticPropsContext } from 'next'; import { ParsedUrlQuery } from 'querystring'; import { ReactElement } from 'react'; import styles from '@styles/pages/Thematic.module.scss'; +import { + getAllThematicsSlug, + getThematicBySlug, +} from '@services/graphql/queries'; const Thematic: NextPageWithLayout<ThematicProps> = ({ thematic }) => { const getPostsList = () => { @@ -66,7 +66,7 @@ export const getStaticProps: GetStaticProps = async ( }; export const getStaticPaths: GetStaticPaths = async () => { - const allSlugs = await fetchAllThematicsSlug(); + const allSlugs = await getAllThematicsSlug(); return { paths: allSlugs.map((post) => `/thematique/${post.slug}`), |
