Skip to content

Commit

Permalink
[chore] mutate isLoading 활용으로 인한 로직 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
Im-younique committed Jun 2, 2024
1 parent 4c58e7c commit ceef248
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 19 deletions.
11 changes: 3 additions & 8 deletions client/src/app/qna/components/QnaComment/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -80,7 +79,7 @@ export default function QnaComment({
});

const queryClient = useQueryClient();
const { mutate } = useMutation({
const { mutate, isLoading } = useMutation({
mutationFn: (content: string) =>
commentManager.updateComment({
content,
Expand All @@ -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 }),
});
Expand Down Expand Up @@ -144,7 +139,7 @@ export default function QnaComment({
<Button
color="blue_gray"
onClick={handleModifyConfirm}
disabled={isSubmitting}
disabled={isLoading}
>
답변 수정
</Button>
Expand Down
14 changes: 3 additions & 11 deletions client/src/app/qna/components/QnaCommentUpload/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use client';

import { useState } from 'react';

// tiptap
import { EditorContent } from '@tiptap/react';

Expand Down Expand Up @@ -33,14 +31,12 @@ export default function QnaCommentUpload({
postOriginId,
user,
}: IQnaCommnetUpload) {
const [isSubmitting, setIsSubmitting] = useState<boolean>(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: () =>
Expand All @@ -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);
},
});
};

Expand All @@ -80,7 +72,7 @@ export default function QnaCommentUpload({
<Button
color="blue_gray"
onClick={handleCommentSubmit}
disabled={isSubmitting || editor === null || editor.getText() === ''}
disabled={isLoading || editor === null || editor.getText() === ''}
>
답변 작성
</Button>
Expand Down

0 comments on commit ceef248

Please sign in to comment.