From a810d9176f99de9c9ad3f92a6158894bb511804d Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Wed, 7 Jun 2023 23:34:50 +0300 Subject: [PATCH] Remove empty comment and mark on cancel --- app/scenes/Document/components/CommentForm.tsx | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/scenes/Document/components/CommentForm.tsx b/app/scenes/Document/components/CommentForm.tsx index cde922d94..858b903a4 100644 --- a/app/scenes/Document/components/CommentForm.tsx +++ b/app/scenes/Document/components/CommentForm.tsx @@ -69,7 +69,7 @@ function CommentForm({ const { comments } = useStores(); const user = useCurrentUser(); - useOnClickOutside(formRef, () => { + const reset = React.useCallback(() => { const isEmpty = editorRef.current?.isEmpty() ?? true; if (isEmpty && thread?.isNew) { @@ -78,7 +78,9 @@ function CommentForm({ } thread.delete(); } - }); + }, [editor, thread]); + + useOnClickOutside(formRef, reset); const handleCreateComment = action(async (event: React.FormEvent) => { event.preventDefault(); @@ -175,6 +177,7 @@ function CommentForm({ setData(undefined); setForceRender((s) => ++s); setInputFocused(false); + reset(); }; const handleFocus = () => {