fix: 좋아요·저장·댓글이 서버에서 실패하면 화면을 되돌리고 알림

This commit is contained in:
minaChoi committed 2026-10-06 10:30:33 +09:00
1 parent 8a5d45c513
commit ae6b06ac1f
2 files changed
+23 -7

No files matched your search

+6 -3
View File
@@ -226,7 +226,7 @@ function FullCard({ post }: PostProps) {
const comments = () => open({ type: 'comments', postId: post.post_id })
const patch = (values: Partial<PostData>) => 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 }),
},
)