diff options
| author | Armand Philippot <git@armandphilippot.com> | 2022-03-01 22:08:56 +0100 |
|---|---|---|
| committer | Armand Philippot <git@armandphilippot.com> | 2022-03-01 22:08:56 +0100 |
| commit | 80d54805e26a6a6971c5ad214b02456dcc226628 (patch) | |
| tree | 9b81e0cd3ff881b2cbeb81f9f96b52b510d67646 /src/components/Comment/Comment.tsx | |
| parent | 99ae0a9d3a923ca1e998dc9b504dad607fdfd768 (diff) | |
| parent | 8bd9784acdee6871ad70e86d0d7120299bf76969 (diff) | |
refactor: various refactoring
Improve maintenance (meta splitting) and try to
improve performance (dynamic imports).
Diffstat (limited to 'src/components/Comment/Comment.tsx')
| -rw-r--r-- | src/components/Comment/Comment.tsx | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/src/components/Comment/Comment.tsx b/src/components/Comment/Comment.tsx index 7215afe..0371288 100644 --- a/src/components/Comment/Comment.tsx +++ b/src/components/Comment/Comment.tsx @@ -1,17 +1,25 @@ import { Button } from '@components/Buttons'; -import CommentForm from '@components/CommentForm/CommentForm'; +import Spinner from '@components/Spinner/Spinner'; import { Comment as CommentData } from '@ts/types/comments'; import { settings } from '@utils/config'; import { getFormattedDate } from '@utils/helpers/format'; +import dynamic from 'next/dynamic'; import Image from 'next/image'; import Link from 'next/link'; import { useRouter } from 'next/router'; import Script from 'next/script'; -import { useEffect, useRef, useState } from 'react'; +import { useState } from 'react'; import { useIntl } from 'react-intl'; import { Comment as CommentSchema, WithContext } from 'schema-dts'; import styles from './Comment.module.scss'; +const DynamicCommentForm = dynamic( + () => import('@components/CommentForm/CommentForm'), + { + loading: () => <Spinner />, + } +); + const Comment = ({ articleId, comment, @@ -25,11 +33,6 @@ const Comment = ({ const router = useRouter(); const locale = router.locale ? router.locale : settings.locales.defaultLocale; const [shouldOpenForm, setShouldOpenForm] = useState<boolean>(false); - const firstFieldRef = useRef<HTMLInputElement>(null); - - useEffect(() => { - firstFieldRef.current && firstFieldRef.current.focus(); - }); const getCommentAuthor = () => { return comment.author.url ? ( @@ -113,8 +116,7 @@ const Comment = ({ )} </article> {shouldOpenForm && ( - <CommentForm - ref={firstFieldRef} + <DynamicCommentForm articleId={articleId} parentId={comment.commentId} /> |
