Преглед изворни кода

Fix cancel a comment reply will close all comment reply editor

https://youtrack.weseek.co.jp/issue/GW-7961
- Create new Set from previousState in removeShowEditorId
- Rename previousShowEditorIds to updatedShowEditorIds
- Create handleReplyButtonClick method
- Apply handleReplyButtonClick to reply Button component
Mudana-Grune пре 2 година
родитељ
комит
d9bef184f4
1 измењених фајлова са 9 додато и 6 уклоњено
  1. 9 6
      apps/app/src/components/PageComment.tsx

+ 9 - 6
apps/app/src/components/PageComment.tsx

@@ -100,12 +100,17 @@ export const PageComment: FC<PageCommentProps> = memo((props:PageCommentProps):
 
 
   const removeShowEditorId = useCallback((commentId: string) => {
   const removeShowEditorId = useCallback((commentId: string) => {
     setShowEditorIds((previousState) => {
     setShowEditorIds((previousState) => {
-      const previousShowEditorIds = new Set(...previousState);
-      previousShowEditorIds.delete(commentId);
-      return previousShowEditorIds;
+      // Create a new Set of commentId from the previous state
+      const updatedShowEditorIds = new Set(previousState);
+      updatedShowEditorIds.delete(commentId);  // Delete the commentId from the Set
+      return updatedShowEditorIds;
     });
     });
   }, []);
   }, []);
 
 
+  const handleReplyButtonClick = useCallback((commentId: string) => {
+    setShowEditorIds((previousState) => new Set(previousState.add(commentId)));
+  }, []);
+
   if (hideIfEmpty && comments?.length === 0) {
   if (hideIfEmpty && comments?.length === 0) {
     return <PageCommentRoot />;
     return <PageCommentRoot />;
   }
   }
@@ -184,9 +189,7 @@ export const PageComment: FC<PageCommentProps> = memo((props:PageCommentProps):
                             color="secondary"
                             color="secondary"
                             size="sm"
                             size="sm"
                             className="btn-comment-reply"
                             className="btn-comment-reply"
-                            onClick={() => {
-                              setShowEditorIds(previousState => new Set(previousState.add(comment._id)));
-                            }}
+                            onClick={() => handleReplyButtonClick(comment._id)}
                           >
                           >
                             <i className="icon-fw icon-action-undo"></i> Reply
                             <i className="icon-fw icon-action-undo"></i> Reply
                           </Button>
                           </Button>