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...). --- .../templates/page/page-layout.module.scss | 11 ------- .../templates/page/page-layout.stories.tsx | 24 +++++---------- src/components/templates/page/page-layout.tsx | 35 +++++++++++----------- 3 files changed, 25 insertions(+), 45 deletions(-) (limited to 'src/components/templates/page') diff --git a/src/components/templates/page/page-layout.module.scss b/src/components/templates/page/page-layout.module.scss index c6b4e8d..c7674ae 100644 --- a/src/components/templates/page/page-layout.module.scss +++ b/src/components/templates/page/page-layout.module.scss @@ -2,17 +2,6 @@ @use "@styles/abstracts/mixins" as mix; @use "@styles/abstracts/placeholders"; -.article { - @extend %grid; - - grid-auto-flow: column dense; - align-items: baseline; - - &--no-comments { - padding-bottom: var(--spacing-lg); - } -} - .breadcrumb { @extend %grid; diff --git a/src/components/templates/page/page-layout.stories.tsx b/src/components/templates/page/page-layout.stories.tsx index 8af5f98..bec1066 100644 --- a/src/components/templates/page/page-layout.stories.tsx +++ b/src/components/templates/page/page-layout.stories.tsx @@ -1,11 +1,11 @@ import ButtonLink from '@components/atoms/buttons/button-link'; import Heading from '@components/atoms/headings/heading'; import Link from '@components/atoms/links/link'; -import ProgressBar from '@components/atoms/loaders/progress-bar'; import PostsList from '@components/organisms/layout/posts-list'; import LinksListWidget from '@components/organisms/widgets/links-list-widget'; import Sharing from '@components/organisms/widgets/sharing'; import { ComponentMeta, ComponentStory } from '@storybook/react'; +import { LayoutBase } from '../layout/layout.stories'; import PageLayoutComponent from './page-layout'; /** @@ -118,20 +118,6 @@ export default { required: false, }, }, - isHome: { - control: { - type: 'boolean', - }, - description: 'Determine if the current page is the homepage.', - table: { - category: 'Options', - defaultValue: { summary: false }, - }, - type: { - name: 'boolean', - required: false, - }, - }, title: { control: { type: 'text', @@ -168,6 +154,13 @@ export default { }, }, }, + decorators: [ + (Story) => ( + + + + ), + ], parameters: { layout: 'fullscreen', }, @@ -477,7 +470,6 @@ Blog.args = { children: ( <> - ), widgets: [ diff --git a/src/components/templates/page/page-layout.tsx b/src/components/templates/page/page-layout.tsx index 2ff2084..d171944 100644 --- a/src/components/templates/page/page-layout.tsx +++ b/src/components/templates/page/page-layout.tsx @@ -21,19 +21,20 @@ import TableOfContents from '@components/organisms/widgets/table-of-contents'; import { type SendCommentVars } from '@services/graphql/api'; import { sendComment } from '@services/graphql/comments'; import useIsMounted from '@utils/hooks/use-is-mounted'; +import Script from 'next/script'; import { FC, HTMLAttributes, ReactNode, useRef, useState } from 'react'; import { useIntl } from 'react-intl'; -import Layout, { type LayoutProps } from '../layout/layout'; +import { BreadcrumbList } from 'schema-dts'; import styles from './page-layout.module.scss'; -export type PageLayoutProps = Pick< - LayoutProps, - 'breadcrumbSchema' | 'isHome' -> & { +export type PageLayoutProps = { /** * True if the page accepts new comments. Default: false. */ allowComments?: boolean; + /** + * Set attributes to the page body. + */ bodyAttributes?: HTMLAttributes; /** * Set additional classnames to the body wrapper. @@ -43,6 +44,10 @@ export type PageLayoutProps = Pick< * The breadcrumb items. */ breadcrumb: BreadcrumbItem[]; + /** + * The breadcrumb JSON schema. + */ + breadcrumbSchema: BreadcrumbList['itemListElement'][]; /** * The main content of the page. */ @@ -98,7 +103,6 @@ const PageLayout: FC = ({ headerMeta, id, intro, - isHome = false, title, widgets, withToC = false, @@ -117,13 +121,7 @@ const PageLayout: FC = ({ const bodyRef = useRef(null); const isMounted = useIsMounted(bodyRef); - const hasComments = Array.isArray(comments) && comments.length > 0; - const articleModifier = - hasComments || allowComments - ? 'article--has-comments' - : 'article--no-comments'; - const [status, setStatus] = useState('info'); const [statusMessage, setStatusMessage] = useState(''); const isReplyRef = useRef(false); @@ -186,11 +184,12 @@ const PageLayout: FC = ({ }; return ( - + <> +