From 2487b4f8b795d0b225c2929dfd6c39f55b106057 Mon Sep 17 00:00:00 2001 From: Lee jin <83453646+j-nary@users.noreply.github.com> Date: Wed, 9 Oct 2024 22:02:15 +0900 Subject: [PATCH 1/2] =?UTF-8?q?fix:=20useMutationPostLike=20type=EC=97=90?= =?UTF-8?q?=EC=84=9C=20data=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/post/hooks.ts | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/api/post/hooks.ts b/src/api/post/hooks.ts index 82e0cb1a..cbbfddf4 100644 --- a/src/api/post/hooks.ts +++ b/src/api/post/hooks.ts @@ -70,9 +70,7 @@ export const useQueryGetPost = (postId: string) => { }); }; -type postType = { - data: paths['/post/v2/{postId}']['get']['responses']['200']['content']['application/json;charset=UTF-8']; -}; +type postType = paths['/post/v2/{postId}']['get']['responses']['200']['content']['application/json;charset=UTF-8']; export const useMutationPostLike = (queryId: string) => { const queryClient = useQueryClient(); @@ -83,13 +81,13 @@ export const useMutationPostLike = (queryId: string) => { onMutate: async () => { const previousPost = queryClient.getQueryData(['getPost', queryId]) as postType; - const newLikeCount = previousPost.data.isLiked - ? previousPost.data.likeCount && previousPost.data.likeCount - 1 - : previousPost.data.likeCount && previousPost.data.likeCount + 1; + const newLikeCount = previousPost.isLiked + ? previousPost.likeCount && previousPost.likeCount - 1 + : previousPost.likeCount && previousPost.likeCount + 1; const data = produce(previousPost, (draft: postType) => { - draft.data.isLiked = !previousPost.data.isLiked; - draft.data.likeCount = newLikeCount; + draft.isLiked = !previousPost.isLiked; + draft.likeCount = newLikeCount; }); queryClient.setQueryData(['getPost', queryId], data); From 2cbdfa1d35b36a8329ff80f75deca970ae9d2b46 Mon Sep 17 00:00:00 2001 From: Lee jin <83453646+j-nary@users.noreply.github.com> Date: Wed, 9 Oct 2024 23:43:54 +0900 Subject: [PATCH 2/2] =?UTF-8?q?refactor:=20API=20=EC=97=85=EB=8D=B0?= =?UTF-8?q?=EC=9D=B4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/__generated__/schema2.d.ts | 2 +- src/api/post/hooks.ts | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/__generated__/schema2.d.ts b/src/__generated__/schema2.d.ts index 72ff081a..6ccd5e4d 100644 --- a/src/__generated__/schema2.d.ts +++ b/src/__generated__/schema2.d.ts @@ -1027,7 +1027,7 @@ export interface components { * @description 게시글 좋아요 갯수 * @example 20 */ - likeCount?: number; + likeCount: number; /** * @description 게시글 좋아요 여부 * @example true diff --git a/src/api/post/hooks.ts b/src/api/post/hooks.ts index cbbfddf4..82f3ce16 100644 --- a/src/api/post/hooks.ts +++ b/src/api/post/hooks.ts @@ -81,9 +81,7 @@ export const useMutationPostLike = (queryId: string) => { onMutate: async () => { const previousPost = queryClient.getQueryData(['getPost', queryId]) as postType; - const newLikeCount = previousPost.isLiked - ? previousPost.likeCount && previousPost.likeCount - 1 - : previousPost.likeCount && previousPost.likeCount + 1; + const newLikeCount = previousPost.isLiked ? previousPost.likeCount - 1 : previousPost.likeCount + 1; const data = produce(previousPost, (draft: postType) => { draft.isLiked = !previousPost.isLiked;