From ae6b06ac1f95016b9b79a11967cc8cfb30090e0b Mon Sep 17 00:00:00 2001 From: Mina Choi Date: Tue, 6 Oct 2026 10:30:33 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=EC=A2=8B=EC=95=84=EC=9A=94=C2=B7?= =?UTF-8?q?=EC=A0=80=EC=9E=A5=C2=B7=EB=8C=93=EA=B8=80=EC=9D=B4=20=EC=84=9C?= =?UTF-8?q?=EB=B2=84=EC=97=90=EC=84=9C=20=EC=8B=A4=ED=8C=A8=ED=95=98?= =?UTF-8?q?=EB=A9=B4=20=ED=99=94=EB=A9=B4=EC=9D=84=20=EB=90=98=EB=8F=8C?= =?UTF-8?q?=EB=A6=AC=EA=B3=A0=20=EC=95=8C=EB=A6=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/b/Post.tsx | 9 ++++++--- frontend/src/b/Sheets.tsx | 21 +++++++++++++++++---- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/frontend/src/b/Post.tsx b/frontend/src/b/Post.tsx index b11e107..854b0a1 100644 --- a/frontend/src/b/Post.tsx +++ b/frontend/src/b/Post.tsx @@ -226,7 +226,7 @@ function FullCard({ post }: PostProps) { const comments = () => open({ type: 'comments', postId: post.post_id }) const patch = (values: Partial) => patchFeed(queryClient, post.post_id, values) - // 화면을 먼저 바꾸고, 실패하면 되돌린다 + // 화면을 먼저 바꾸고, 실패하면 되돌린다 (서버는 실패도 200 + result.success=false 로 준다) const setLike = (on: boolean) => { if (!loggedIn) return open({ type: 'login' }) if (on === liked) return @@ -235,7 +235,10 @@ function FullCard({ post }: PostProps) { ;(on ? like : unlike).mutate( { path: { post_id: post.post_id } }, { - onSuccess: (res) => patch({ liked: res.liked ?? on, ...(res.like_count != null ? { like_count: res.like_count } : {}) }), + onSuccess: (res) => + res.result?.success + ? patch({ liked: res.liked ?? on, ...(res.like_count != null ? { like_count: res.like_count } : {}) }) + : patch({ liked, like_count: likeCount }), onError: () => patch({ liked, like_count: likeCount }), }, ) @@ -248,7 +251,7 @@ function FullCard({ post }: PostProps) { ;(on ? save : unsave).mutate( { path: { post_id: post.post_id } }, { - onSuccess: (res) => patch({ saved: res.saved ?? on }), + onSuccess: (res) => patch({ saved: res.result?.success ? (res.saved ?? on) : saved }), onError: () => patch({ saved }), }, ) diff --git a/frontend/src/b/Sheets.tsx b/frontend/src/b/Sheets.tsx index 6c825ca..c128afa 100644 --- a/frontend/src/b/Sheets.tsx +++ b/frontend/src/b/Sheets.tsx @@ -422,6 +422,7 @@ function CommentRow({ c, postId }: { c: CommentData; postId: number }) { const like = useMutation(likeCommentMutation()) const unlike = useMutation(unlikeCommentMutation()) const remove = useMutation(deleteCommentMutation()) + const [removeFailed, setRemoveFailed] = useState(false) const toggle = () => { if (!loggedIn) return open({ type: 'login' }) @@ -432,6 +433,11 @@ function CommentRow({ c, postId }: { c: CommentData; postId: number }) { { path: { comment_id: c.comment_id } }, { onSuccess: (res) => { + if (!res.result?.success) { + setLiked(!next) + setCount(c.like_count) + return + } setLiked(!!res.liked) if (res.like_count != null) setCount(res.like_count) }, @@ -447,10 +453,13 @@ function CommentRow({ c, postId }: { c: CommentData; postId: number }) { remove.mutate( { path: { comment_id: c.comment_id } }, { - onSuccess: () => { + onSuccess: (res) => { + setRemoveFailed(!res.result?.success) + if (!res.result?.success) return queryClient.invalidateQueries({ queryKey: listCommentsQueryKey({ path: { post_id: postId } }) }) queryClient.invalidateQueries({ queryKey: getFeedQueryKey({ query: { region: region.code } }) }) }, + onError: () => setRemoveFailed(true), }, ) @@ -473,7 +482,7 @@ function CommentRow({ c, postId }: { c: CommentData; postId: number }) { )} - {remove.isError && 지우지 못했어요. 다시 해 주세요.} + {removeFailed && 지우지 못했어요. 다시 해 주세요.} ))} - {add.isError && ( + {addFailed && (

댓글을 올리지 못했어요. 다시 해 주세요.