From ceef2485b87075b5bc78d55d90bb96ac5d0ae5f4 Mon Sep 17 00:00:00 2001 From: Im-younique Date: Sun, 2 Jun 2024 21:32:37 +0900 Subject: [PATCH] =?UTF-8?q?[chore]=20mutate=20isLoading=20=ED=99=9C?= =?UTF-8?q?=EC=9A=A9=EC=9C=BC=EB=A1=9C=20=EC=9D=B8=ED=95=9C=20=EB=A1=9C?= =?UTF-8?q?=EC=A7=81=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- client/src/app/qna/components/QnaComment/index.tsx | 11 +++-------- .../app/qna/components/QnaCommentUpload/index.tsx | 14 +++----------- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/client/src/app/qna/components/QnaComment/index.tsx b/client/src/app/qna/components/QnaComment/index.tsx index ec0d5fd..3ad8d12 100644 --- a/client/src/app/qna/components/QnaComment/index.tsx +++ b/client/src/app/qna/components/QnaComment/index.tsx @@ -59,7 +59,6 @@ export default function QnaComment({ const [isReplying, setIsReplying] = useState(false); const [isReplyOpen, setIsReplyOpen] = useState(false); const [isModifying, setIsModifying] = useState(false); - const [isSubmitting, setIsSubmitting] = useState(false); const childCount = React.Children.count(children); @@ -80,7 +79,7 @@ export default function QnaComment({ }); const queryClient = useQueryClient(); - const { mutate } = useMutation({ + const { mutate, isLoading } = useMutation({ mutationFn: (content: string) => commentManager.updateComment({ content, @@ -95,12 +94,8 @@ export default function QnaComment({ openModal({ type: ModalType.ERROR, message: errorMessage.blankComment }); return; } - setIsSubmitting(true); mutate(editor.getHTML(), { - onSuccess: () => { - setIsModifying(false); - setIsSubmitting(false); - }, + onSuccess: () => setIsModifying(false), onError: () => openModal({ type: ModalType.ERROR, message: errorMessage.tryAgain }), }); @@ -144,7 +139,7 @@ export default function QnaComment({ diff --git a/client/src/app/qna/components/QnaCommentUpload/index.tsx b/client/src/app/qna/components/QnaCommentUpload/index.tsx index b56329c..85c1819 100644 --- a/client/src/app/qna/components/QnaCommentUpload/index.tsx +++ b/client/src/app/qna/components/QnaCommentUpload/index.tsx @@ -1,7 +1,5 @@ 'use client'; -import { useState } from 'react'; - // tiptap import { EditorContent } from '@tiptap/react'; @@ -33,14 +31,12 @@ export default function QnaCommentUpload({ postOriginId, user, }: IQnaCommnetUpload) { - const [isSubmitting, setIsSubmitting] = useState(false); - const { openModal } = useModal(); const { editor } = useTipTap({ placeholder: '답변을 작성해주세요.' }); const queryClient = useQueryClient(); - const { mutate } = useMutation({ + const { mutate, isLoading } = useMutation({ mutationFn: (content: string) => commentManager.createComment({ content, postOriginId }), onSuccess: () => @@ -56,17 +52,13 @@ export default function QnaCommentUpload({ openModal({ type: ModalType.ERROR, message: errorMessage.blankComment }); return; } - setIsSubmitting(true); mutate(editor.getHTML(), { onSuccess: () => { editor.commands.setContent(''); setTimeout(() => window.scrollTo(0, document.body.scrollHeight), 100); - setIsSubmitting(false); }, - onError: () => { + onError: () => openModal({ type: ModalType.ERROR, message: errorMessage.tryAgain }), - setIsSubmitting(false); - }, }); }; @@ -80,7 +72,7 @@ export default function QnaCommentUpload({