From 6f46e54e382bf3f535f27ebead18c2bdf4628e49 Mon Sep 17 00:00:00 2001 From: Armand Philippot Date: Sat, 15 Jan 2022 23:08:25 +0100 Subject: chore(comments): handle comment reply --- src/components/Comment/Comment.tsx | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) (limited to 'src/components/Comment') diff --git a/src/components/Comment/Comment.tsx b/src/components/Comment/Comment.tsx index 6a4abce..e0a65f3 100644 --- a/src/components/Comment/Comment.tsx +++ b/src/components/Comment/Comment.tsx @@ -1,19 +1,29 @@ import { Button } from '@components/Buttons'; +import CommentForm from '@components/CommentForm/CommentForm'; import { t } from '@lingui/macro'; import { Comment as CommentData } from '@ts/types/comments'; import Image from 'next/image'; import Link from 'next/link'; import { useRouter } from 'next/router'; +import { useEffect, useRef, useState } from 'react'; import styles from './Comment.module.scss'; const Comment = ({ + articleId, comment, isNested = false, }: { + articleId: number; comment: CommentData; isNested?: boolean; }) => { const router = useRouter(); + const [isReply, setIsReply] = useState(false); + const firstFieldRef = useRef(null); + + useEffect(() => { + firstFieldRef.current && firstFieldRef.current.focus(); + }); const getCommentAuthor = () => { return comment.author.url ? ( @@ -71,14 +81,31 @@ const Comment = ({ > {!isNested && (
- +
)} + {isReply && ( + + )} {comment.replies.length > 0 && (
    {comment.replies.map((reply) => { - return ; + return ( + + ); })}
)} -- cgit v1.2.3