Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useMutationPostLike type에서 data 제거 #917

Merged
merged 2 commits into from
Oct 9, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions src/api/post/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Copy link
Contributor

@borimong borimong Oct 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

슬랙에서도 이야기했었지만, 이렇게 될 경우 likeCount 가 0 이 될 때 falsy 한 값으로 처리되게 되어요. 그래서 제가 슬랙에 보내드린 사진처럼 || 0 을 활용하거나, 서버 api 에서 타입을 undefined | number > number 로 바꾸어주어야 해요~

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

앗 네 ..! 서버 api 타입 변경까지 pending 하겠습니다!!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

반영 완료했습니다!

: 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;
Comment on lines +87 to +88
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아 한번 더 감싸서 오는 에러가 있었구나..!
잘 찾아냈네요 굿굿

});

queryClient.setQueryData(['getPost', queryId], data);
Expand Down
Loading