diff options
| author | Armand Philippot <git@armandphilippot.com> | 2023-11-09 17:18:46 +0100 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2023-11-11 18:15:27 +0100 |
| commit | f699802b837d7d9fcf150ff2bf00cd3c5475c87a (patch) | |
| tree | 6c96a140193e7386b454b6d444058a99a0e07454 /src/components/templates | |
| parent | bd9c9ae7e2ae973969569dd434836de9f38b07d4 (diff) | |
refactor(components): rewrite CommentsList component
* use ApprovedCommentProps to make CommentData type
* add the author name of the parent on reply form heading
* add tests
Diffstat (limited to 'src/components/templates')
| -rw-r--r-- | src/components/templates/page/page-layout.stories.tsx | 104 | ||||
| -rw-r--r-- | src/components/templates/page/page-layout.test.tsx | 11 | ||||
| -rw-r--r-- | src/components/templates/page/page-layout.tsx | 14 |
3 files changed, 113 insertions, 16 deletions
diff --git a/src/components/templates/page/page-layout.stories.tsx b/src/components/templates/page/page-layout.stories.tsx index 05b47da..4086fcd 100644 --- a/src/components/templates/page/page-layout.stories.tsx +++ b/src/components/templates/page/page-layout.stories.tsx @@ -1,7 +1,6 @@ import type { ComponentMeta, ComponentStory } from '@storybook/react'; import { ButtonLink, Heading, Link } from '../../atoms'; import { LinksListWidget, PostsList, Sharing } from '../../organisms'; -import { comments } from '../../organisms/layout/comments-list.fixture'; import { posts } from '../../organisms/layout/posts-list.fixture'; import { LayoutBase } from '../layout/layout.stories'; import { PageLayout as PageLayoutComponent } from './page-layout'; @@ -346,7 +345,108 @@ Post.args = { />, ], withToC: true, - comments, + comments: [ + { + author: { + name: 'Milan0', + avatar: { + alt: 'Milan0 avatar', + src: 'https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar/976.jpg', + }, + }, + content: 'Fugit veniam quas qui dolor explicabo.', + id: 1, + isApproved: true, + publicationDate: '2023-01-23', + replies: [ + { + author: { name: 'Haskell42' }, + content: 'Error quas accusamus nesciunt enim quae a.', + id: 25, + isApproved: true, + publicationDate: '2023-02-04', + }, + { + author: { + name: 'Hanna49', + website: 'https://www.armandphilippot.com', + }, + content: 'Ut ducimus neque aliquam soluta sed totam commodi cum sit.', + id: 30, + isApproved: true, + publicationDate: '2023-03-10', + }, + ], + }, + { + author: { + name: 'Corrine9', + avatar: { + alt: 'Corrine9 avatar', + src: 'https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar/539.jpg', + }, + }, + content: + 'Dolore hic iure voluptatum quam error minima. Quas ut aperiam sit commodi cumque consequatur. Voluptas debitis veritatis officiis in voluptas ea et laborum animi. Voluptatem qui enim neque. Et sunt quo neque assumenda iure. Non vel ut consectetur.', + id: 2, + isApproved: true, + publicationDate: '2023-04-20', + }, + { + author: { name: 'Presley12' }, + content: + 'Nulla eaque similique recusandae enim aut eligendi iure consequatur. Et aut qui. Voluptatem a voluptatem consequatur aliquid distinctio ex culpa. Adipisci animi amet reprehenderit autem quia commodi voluptatum commodi.', + id: 3, + isApproved: true, + publicationDate: '2023-05-01', + replies: [ + { + author: { + name: 'Ana_Haley33', + avatar: { + alt: 'Ana_Haley33 avatar', + src: 'https://cloudflare-ipfs.com/ipfs/Qmd3W5DuhgHirLHGVixi6V76LhCkZUz6pnFt5AJBiyvHye/avatar/881.jpg', + }, + }, + content: 'Ab ea et fugit autem.', + id: 17, + isApproved: true, + publicationDate: '2023-05-01', + }, + { + author: { name: 'Santos.Harris17' }, + content: + 'Illo dolores voluptatem similique voluptas quasi hic aspernatur ab nisi.', + id: 18, + isApproved: false, + publicationDate: '2023-05-02', + }, + ], + }, + { + author: { name: 'Julius.Borer' }, + content: + 'Ea fugit totam et voluptatum quidem laborum explicabo fuga quod.', + id: 4, + isApproved: true, + publicationDate: '2023-06-15', + }, + { + author: { name: 'Geo87' }, + content: + 'Enim consequatur deleniti aliquid adipisci. Et mollitia saepe vel rerum totam praesentium assumenda repellat fuga. Ipsum ut architecto consequatur. Ut laborum suscipit sed corporis quas aliquid. Et et omnis quo. Dolore quia ipsum ut corporis eum et corporis qui.', + id: 5, + isApproved: false, + publicationDate: '2023-06-16', + }, + { + author: { name: 'Kurt.Keeling' }, + content: 'Eligendi repellat officiis amet.', + id: 6, + isApproved: true, + publicationDate: '2023-06-17', + }, + ], allowComments: true, }; diff --git a/src/components/templates/page/page-layout.test.tsx b/src/components/templates/page/page-layout.test.tsx index 394f995..c7d7a65 100644 --- a/src/components/templates/page/page-layout.test.tsx +++ b/src/components/templates/page/page-layout.test.tsx @@ -1,7 +1,6 @@ import { describe, expect, it } from '@jest/globals'; import type { BreadcrumbList } from 'schema-dts'; import { render, screen as rtlScreen } from '../../../../tests/utils'; -import { comments } from '../../organisms/layout/comments-list.fixture'; import { PageLayout } from './page-layout'; const title = 'Incidunt ad earum'; @@ -94,7 +93,15 @@ describe('PageLayout', () => { breadcrumbSchema={breadcrumbSchema} title={title} allowComments={true} - comments={comments} + comments={[ + { + author: { name: 'Burley40' }, + content: 'Veritatis praesentium non autem ut.', + id: 1, + isApproved: true, + publicationDate: '2023-11-02', + }, + ]} > {children} </PageLayout> diff --git a/src/components/templates/page/page-layout.tsx b/src/components/templates/page/page-layout.tsx index 434b8ff..28c850b 100644 --- a/src/components/templates/page/page-layout.tsx +++ b/src/components/templates/page/page-layout.tsx @@ -9,7 +9,7 @@ import { import { useIntl } from 'react-intl'; import type { BreadcrumbList } from 'schema-dts'; import { sendComment } from '../../../services/graphql'; -import type { SendCommentInput, SingleComment } from '../../../types'; +import type { SendCommentInput } from '../../../types'; import { useIsMounted } from '../../../utils/hooks'; import { Heading, Sidebar } from '../../atoms'; import { @@ -29,16 +29,6 @@ import { } from '../../organisms'; import styles from './page-layout.module.scss'; -/** - * Check if there is at least one comment. - * - * @param {SingleComment[] | undefined} comments - The comments. - */ -const hasComments = ( - comments: SingleComment[] | undefined -): comments is SingleComment[] => - Array.isArray(comments) && comments.length > 0; - export type PageLayoutProps = { /** * True if the page accepts new comments. Default: false. @@ -262,7 +252,7 @@ export const PageLayout: FC<PageLayoutProps> = ({ <Heading className={styles.comments__title} level={2}> {commentsTitle} </Heading> - {hasComments(comments) ? ( + {comments?.length ? ( <CommentsList comments={comments} depth={2} |
