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/components/templates/layout/layout.tsx | 54 ++++++++++++++++++------------ 1 file changed, 32 insertions(+), 22 deletions(-) (limited to 'src/components/templates/layout/layout.tsx') diff --git a/src/components/templates/layout/layout.tsx b/src/components/templates/layout/layout.tsx index 3eb02ee..559eaed 100644 --- a/src/components/templates/layout/layout.tsx +++ b/src/components/templates/layout/layout.tsx @@ -9,18 +9,13 @@ import Main from '@components/atoms/layout/main'; import NoScript from '@components/atoms/layout/no-script'; import Footer, { type FooterProps } from '@components/organisms/layout/footer'; import Header, { type HeaderProps } from '@components/organisms/layout/header'; +import { type NextPageWithLayoutOptions } from '@ts/types/app'; import useScrollPosition from '@utils/hooks/use-scroll-position'; import useSettings from '@utils/hooks/use-settings'; import Script from 'next/script'; -import { FC, ReactNode, useState } from 'react'; +import { FC, ReactElement, ReactNode, useState } from 'react'; import { useIntl } from 'react-intl'; -import { - BreadcrumbList, - Person, - SearchAction, - WebSite, - WithContext, -} from 'schema-dts'; +import { Person, SearchAction, WebSite, WithContext } from 'schema-dts'; import styles from './layout.module.scss'; export type QueryAction = SearchAction & { @@ -28,18 +23,18 @@ export type QueryAction = SearchAction & { }; export type LayoutProps = Pick & { - /** - * The breadcrumb JSON schema. - */ - breadcrumbSchema: BreadcrumbList['itemListElement'][]; /** * The layout main content. */ children: ReactNode; /** - * Set additional classnames to the article element. + * Determine if article has a comments section. + */ + withExtraPadding?: boolean; + /** + * Determine if article should use grid. Default: false. */ - className?: string; + useGrid?: boolean; }; /** @@ -48,14 +43,16 @@ export type LayoutProps = Pick & { * Render the base layout used by all pages. */ const Layout: FC = ({ - breadcrumbSchema, children, + withExtraPadding = false, isHome, - ...props + useGrid = false, }) => { const intl = useIntl(); const { website } = useSettings(); const { baseline, copyright, locales, name, picture, url } = website; + const articleGridClass = useGrid ? 'article--grid' : ''; + const articleCommentsClass = withExtraPadding ? 'article--padding' : ''; const skipToContent = intl.formatMessage({ defaultMessage: 'Skip to content', @@ -188,11 +185,6 @@ const Layout: FC = ({ type="application/ld+json" dangerouslySetInnerHTML={{ __html: JSON.stringify(brandingSchema) }} /> -