From 271ef6debaca7ed9a01829dcef3a37e90a2dff05 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Tue, 17 May 2022 22:48:41 +0200 Subject: chore: use persistent layout It prevents to rerender the common components between pages (header, footer...). --- src/pages/404.tsx | 9 +++++++-- src/pages/_app.tsx | 7 ++++--- src/pages/article/[slug].tsx | 16 +++++++++++++--- src/pages/blog/index.tsx | 14 +++++++++++--- src/pages/contact.tsx | 11 ++++++++--- src/pages/cv.tsx | 9 +++++++-- src/pages/index.tsx | 20 ++++++++++++++------ src/pages/mentions-legales.tsx | 9 +++++++-- src/pages/projets/[slug].tsx | 14 +++++++++++--- src/pages/projets/index.tsx | 10 +++++++--- src/pages/recherche/index.tsx | 14 +++++++++++--- src/pages/sujet/[slug].tsx | 18 +++++++++++++++--- src/pages/thematique/[slug].tsx | 15 ++++++++++++--- 13 files changed, 127 insertions(+), 39 deletions(-) (limited to 'src/pages') diff --git a/src/pages/404.tsx b/src/pages/404.tsx index 4f6e22d..4ab7784 100644 --- a/src/pages/404.tsx +++ b/src/pages/404.tsx @@ -1,11 +1,13 @@ import Link from '@components/atoms/links/link'; import LinksListWidget from '@components/organisms/widgets/links-list-widget'; +import { getLayout } from '@components/templates/layout/layout'; import PageLayout from '@components/templates/page/page-layout'; import { getThematicsPreview, getTotalThematics, } from '@services/graphql/thematics'; import { getTopicsPreview, getTotalTopics } from '@services/graphql/topics'; +import { type NextPageWithLayout } from '@ts/types/app'; import { type RawThematicPreview, type RawTopicPreview, @@ -17,7 +19,7 @@ import { } from '@utils/helpers/pages'; import useBreadcrumb from '@utils/hooks/use-breadcrumb'; import useSettings from '@utils/hooks/use-settings'; -import { GetStaticProps, NextPage } from 'next'; +import { GetStaticProps } from 'next'; import Head from 'next/head'; import { ReactNode } from 'react'; import { useIntl } from 'react-intl'; @@ -31,7 +33,7 @@ type Error404PageProps = { /** * Error 404 page. */ -const Error404Page: NextPage = ({ +const Error404Page: NextPageWithLayout = ({ thematicsList, topicsList, }) => { @@ -119,6 +121,9 @@ const Error404Page: NextPage = ({ ); }; +Error404Page.getLayout = (page) => + getLayout(page, { useGrid: true, withExtraPadding: true }); + export const getStaticProps: GetStaticProps = async ({ locale, }) => { diff --git a/src/pages/_app.tsx b/src/pages/_app.tsx index 939b337..5bc9f85 100644 --- a/src/pages/_app.tsx +++ b/src/pages/_app.tsx @@ -1,15 +1,16 @@ +import { type AppPropsWithLayout } from '@ts/types/app'; import { settings } from '@utils/config'; import { AckeeProvider } from '@utils/providers/ackee'; import { PrismThemeProvider } from '@utils/providers/prism-theme'; import { ThemeProvider } from 'next-themes'; -import { AppProps } from 'next/app'; import { useRouter } from 'next/router'; import { IntlProvider } from 'react-intl'; import '../styles/globals.scss'; -const App = ({ Component, pageProps }: AppProps) => { +const App = ({ Component, pageProps }: AppPropsWithLayout) => { const { locale, defaultLocale } = useRouter(); const appLocale: string = locale || settings.locales.defaultLocale; + const getLayout = Component.getLayout ?? ((page) => page); return ( @@ -24,7 +25,7 @@ const App = ({ Component, pageProps }: AppProps) => { enableSystem={true} > - + {getLayout(, {})} diff --git a/src/pages/article/[slug].tsx b/src/pages/article/[slug].tsx index a0fb7fc..a3df43b 100644 --- a/src/pages/article/[slug].tsx +++ b/src/pages/article/[slug].tsx @@ -2,6 +2,7 @@ import ButtonLink from '@components/atoms/buttons/button-link'; import Link from '@components/atoms/links/link'; import ResponsiveImage from '@components/molecules/images/responsive-image'; import Sharing from '@components/organisms/widgets/sharing'; +import { getLayout } from '@components/templates/layout/layout'; import PageLayout, { type PageLayoutProps, } from '@components/templates/page/page-layout'; @@ -11,7 +12,11 @@ import { } from '@services/graphql/articles'; import { getPostComments } from '@services/graphql/comments'; import styles from '@styles/pages/article.module.scss'; -import { type Article, type Comment } from '@ts/types/app'; +import { + type Article, + type Comment, + type NextPageWithLayout, +} from '@ts/types/app'; import { loadTranslation, type Messages } from '@utils/helpers/i18n'; import useAddPrismClassAttr from '@utils/hooks/use-add-prism-class-attr'; import useBreadcrumb from '@utils/hooks/use-breadcrumb'; @@ -20,7 +25,7 @@ import usePrismPlugins, { } from '@utils/hooks/use-prism-plugins'; import useReadingTime from '@utils/hooks/use-reading-time'; import useSettings from '@utils/hooks/use-settings'; -import { GetStaticPaths, GetStaticProps, NextPage } from 'next'; +import { GetStaticPaths, GetStaticProps } from 'next'; import Head from 'next/head'; import { useRouter } from 'next/router'; import Script from 'next/script'; @@ -39,7 +44,10 @@ type ArticlePageProps = { /** * Article page. */ -const ArticlePage: NextPage = ({ comments, post }) => { +const ArticlePage: NextPageWithLayout = ({ + comments, + post, +}) => { const { content, id, intro, meta, slug, title } = post; const { author, @@ -252,6 +260,8 @@ const ArticlePage: NextPage = ({ comments, post }) => { ); }; +ArticlePage.getLayout = (page) => getLayout(page, { useGrid: true }); + interface PostParams extends ParsedUrlQuery { slug: string; } diff --git a/src/pages/blog/index.tsx b/src/pages/blog/index.tsx index b6ce221..2676305 100644 --- a/src/pages/blog/index.tsx +++ b/src/pages/blog/index.tsx @@ -1,6 +1,7 @@ import Notice from '@components/atoms/layout/notice'; import PostsList, { type Post } from '@components/organisms/layout/posts-list'; import LinksListWidget from '@components/organisms/widgets/links-list-widget'; +import { getLayout } from '@components/templates/layout/layout'; import PageLayout from '@components/templates/page/page-layout'; import { type EdgesResponse } from '@services/graphql/api'; import { @@ -13,7 +14,11 @@ import { getTotalThematics, } from '@services/graphql/thematics'; import { getTopicsPreview, getTotalTopics } from '@services/graphql/topics'; -import { type Article, type Meta } from '@ts/types/app'; +import { + type Article, + type Meta, + type NextPageWithLayout, +} from '@ts/types/app'; import { RawThematicPreview, RawTopicPreview, @@ -28,7 +33,7 @@ import { import useBreadcrumb from '@utils/hooks/use-breadcrumb'; import usePagination from '@utils/hooks/use-pagination'; import useSettings from '@utils/hooks/use-settings'; -import { GetStaticProps, NextPage } from 'next'; +import { GetStaticProps } from 'next'; import Head from 'next/head'; import { useRouter } from 'next/router'; import Script from 'next/script'; @@ -46,7 +51,7 @@ type BlogPageProps = { /** * Blog index page. */ -const BlogPage: NextPage = ({ +const BlogPage: NextPageWithLayout = ({ articles, thematicsList, topicsList, @@ -268,6 +273,9 @@ const BlogPage: NextPage = ({ ); }; +BlogPage.getLayout = (page) => + getLayout(page, { useGrid: true, withExtraPadding: true }); + export const getStaticProps: GetStaticProps = async ({ locale, }) => { diff --git a/src/pages/contact.tsx b/src/pages/contact.tsx index 617117b..c0d6c79 100644 --- a/src/pages/contact.tsx +++ b/src/pages/contact.tsx @@ -3,22 +3,24 @@ import ContactForm, { type ContactFormProps, } from '@components/organisms/forms/contact-form'; import SocialMedia from '@components/organisms/widgets/social-media'; +import { getLayout } from '@components/templates/layout/layout'; import PageLayout from '@components/templates/page/page-layout'; import { meta } from '@content/pages/contact.mdx'; import styles from '@styles/pages/contact.module.scss'; import { sendMail } from '@services/graphql/contact'; +import { type NextPageWithLayout } from '@ts/types/app'; import { loadTranslation } from '@utils/helpers/i18n'; +import useBreadcrumb from '@utils/hooks/use-breadcrumb'; import useSettings from '@utils/hooks/use-settings'; -import { GetStaticProps, NextPage } from 'next'; +import { GetStaticProps } from 'next'; import Head from 'next/head'; import { useRouter } from 'next/router'; import Script from 'next/script'; import { useState } from 'react'; import { useIntl } from 'react-intl'; import { ContactPage as ContactPageSchema, Graph, WebPage } from 'schema-dts'; -import useBreadcrumb from '@utils/hooks/use-breadcrumb'; -const ContactPage: NextPage = () => { +const ContactPage: NextPageWithLayout = () => { const { dates, intro, seo, title } = meta; const intl = useIntl(); const { items: breadcrumbItems, schema: breadcrumbSchema } = useBreadcrumb({ @@ -164,6 +166,9 @@ const ContactPage: NextPage = () => { ); }; +ContactPage.getLayout = (page) => + getLayout(page, { useGrid: true, withExtraPadding: true }); + export const getStaticProps: GetStaticProps = async ({ locale }) => { const translation = await loadTranslation(locale); diff --git a/src/pages/cv.tsx b/src/pages/cv.tsx index 7936c84..3f035d8 100644 --- a/src/pages/cv.tsx +++ b/src/pages/cv.tsx @@ -3,16 +3,18 @@ import Link from '@components/atoms/links/link'; import List from '@components/atoms/lists/list'; import ImageWidget from '@components/organisms/widgets/image-widget'; import SocialMedia from '@components/organisms/widgets/social-media'; +import { getLayout } from '@components/templates/layout/layout'; import PageLayout, { type PageLayoutProps, } from '@components/templates/page/page-layout'; import CVContent, { data, meta } from '@content/pages/cv.mdx'; import styles from '@styles/pages/cv.module.scss'; +import { type NextPageWithLayout } from '@ts/types/app'; import { loadTranslation } from '@utils/helpers/i18n'; import useBreadcrumb from '@utils/hooks/use-breadcrumb'; import useSettings from '@utils/hooks/use-settings'; import { NestedMDXComponents } from 'mdx/types'; -import { GetStaticProps, NextPage } from 'next'; +import { GetStaticProps } from 'next'; import Head from 'next/head'; import { useRouter } from 'next/router'; import Script from 'next/script'; @@ -23,7 +25,7 @@ import { AboutPage, Graph, WebPage } from 'schema-dts'; /** * CV page. */ -const CVPage: NextPage = () => { +const CVPage: NextPageWithLayout = () => { const intl = useIntl(); const { file, image } = data; const { dates, intro, seo, title } = meta; @@ -186,6 +188,9 @@ const CVPage: NextPage = () => { ); }; +CVPage.getLayout = (page) => + getLayout(page, { useGrid: true, withExtraPadding: true }); + export const getStaticProps: GetStaticProps = async ({ locale }) => { const translation = await loadTranslation(locale); diff --git a/src/pages/index.tsx b/src/pages/index.tsx index 1143a33..a831ea3 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -13,16 +13,16 @@ import Columns, { import CardsList, { type CardsListItem, } from '@components/organisms/layout/cards-list'; -import Layout from '@components/templates/layout/layout'; +import { getLayout } from '@components/templates/layout/layout'; import HomePageContent from '@content/pages/homepage.mdx'; import { getArticlesCard } from '@services/graphql/articles'; import styles from '@styles/pages/home.module.scss'; -import { ArticleCard } from '@ts/types/app'; +import { type ArticleCard, type NextPageWithLayout } from '@ts/types/app'; import { loadTranslation, type Messages } from '@utils/helpers/i18n'; import useBreadcrumb from '@utils/hooks/use-breadcrumb'; import useSettings from '@utils/hooks/use-settings'; import { NestedMDXComponents } from 'mdx/types'; -import { GetStaticProps, NextPage } from 'next'; +import { GetStaticProps } from 'next'; import Head from 'next/head'; import Script from 'next/script'; import { ReactElement } from 'react'; @@ -37,7 +37,7 @@ type HomeProps = { /** * Home page. */ -const HomePage: NextPage = ({ recentPosts }) => { +const HomePage: NextPageWithLayout = ({ recentPosts }) => { const intl = useIntl(); const { schema: breadcrumbSchema } = useBreadcrumb({ title: '', @@ -327,7 +327,7 @@ const HomePage: NextPage = ({ recentPosts }) => { }; return ( - + <> {pageTitle} @@ -340,11 +340,19 @@ const HomePage: NextPage = ({ recentPosts }) => { type="application/ld+json" dangerouslySetInnerHTML={{ __html: JSON.stringify(schemaJsonLd) }} /> +