From 1b34f85f0e3188861c6804666f02b4495cab033c Mon Sep 17 00:00:00 2001
From: Armand Philippot <git@armandphilippot.com>
Date: Mon, 14 Feb 2022 15:48:34 +0100
Subject: chore: improve comment form user experience

---
 src/components/Comment/Comment.tsx | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

(limited to 'src/components/Comment/Comment.tsx')

diff --git a/src/components/Comment/Comment.tsx b/src/components/Comment/Comment.tsx
index ab1dffc..a263771 100644
--- a/src/components/Comment/Comment.tsx
+++ b/src/components/Comment/Comment.tsx
@@ -24,7 +24,7 @@ const Comment = ({
   const intl = useIntl();
   const router = useRouter();
   const locale = router.locale ? router.locale : settings.locales.defaultLocale;
-  const [isReply, setIsReply] = useState<boolean>(false);
+  const [shouldOpenForm, setShouldOpenForm] = useState<boolean>(false);
   const firstFieldRef = useRef<HTMLInputElement>(null);
 
   useEffect(() => {
@@ -98,21 +98,25 @@ const Comment = ({
           ></div>
           {!isNested && (
             <footer className={styles.footer}>
-              <Button clickHandler={() => setIsReply((prev) => !prev)}>
-                {intl.formatMessage({
-                  defaultMessage: 'Reply',
-                  description: 'Comment: reply button',
-                })}
+              <Button clickHandler={() => setShouldOpenForm((prev) => !prev)}>
+                {shouldOpenForm
+                  ? intl.formatMessage({
+                      defaultMessage: 'Cancel reply',
+                      description: 'Comment: reply button',
+                    })
+                  : intl.formatMessage({
+                      defaultMessage: 'Reply',
+                      description: 'Comment: reply button',
+                    })}
               </Button>
             </footer>
           )}
         </article>
-        {isReply && (
+        {shouldOpenForm && (
           <CommentForm
             ref={firstFieldRef}
             articleId={articleId}
             parentId={comment.commentId}
-            isReply={isReply}
           />
         )}
         {comment.replies.length > 0 && (
-- 
cgit v1.2.3

