-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* feat: bookmark 기능 구현 - api, query 함수명에 명확히 bookmark를 포함하도록 수정 * feat: 책 코멘트 작성 기능 구현 * feat: 코멘트 수정 기능 구현 * refactor: 코멘트 수정 mutation 파라미터 구조 수정 * feat: 코멘트 삭제 기능 구현 * fix: 코드리뷰 반영
- Loading branch information
Showing
18 changed files
with
359 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
|
||
import { APIBook } from '@/types/book'; | ||
import bookAPI from '@/apis/book'; | ||
import bookKeys from './key'; | ||
|
||
const useCreateBookCommentMutation = (bookId: APIBook['bookId']) => { | ||
const queryClient = useQueryClient(); | ||
|
||
return useMutation({ | ||
mutationFn: (newComment: string) => | ||
bookAPI.creaetComment(bookId, newComment).then(({ data }) => data), | ||
onSuccess: () => { | ||
queryClient.invalidateQueries({ queryKey: bookKeys.comments(bookId) }); | ||
}, | ||
}); | ||
}; | ||
|
||
export default useCreateBookCommentMutation; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
|
||
import { APIBook, APIBookComment } from '@/types/book'; | ||
import bookAPI from '@/apis/book'; | ||
import bookKeys from './key'; | ||
|
||
const useDeleteBookCommentMutation = (bookId: APIBook['bookId']) => { | ||
const queryClient = useQueryClient(); | ||
|
||
return useMutation({ | ||
mutationFn: (commentId: APIBookComment['commentId']) => | ||
bookAPI.deletComment(bookId, commentId).then(({ data }) => data), | ||
onSuccess: () => { | ||
queryClient.invalidateQueries({ queryKey: bookKeys.comments(bookId) }); | ||
}, | ||
}); | ||
}; | ||
|
||
export default useDeleteBookCommentMutation; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
|
||
import { APIBook, APIBookComment } from '@/types/book'; | ||
import bookAPI from '@/apis/book'; | ||
import bookKeys from './key'; | ||
|
||
const usePatchBookCommentMutation = (bookId: APIBook['bookId']) => { | ||
const queryClient = useQueryClient(); | ||
|
||
return useMutation({ | ||
mutationFn: (data: { | ||
commentId: APIBookComment['commentId']; | ||
comment: string; | ||
}) => bookAPI.patchComment({ bookId, data }).then(({ data }) => data), | ||
onSettled: () => { | ||
queryClient.invalidateQueries({ queryKey: bookKeys.comments(bookId) }); | ||
}, | ||
}); | ||
}; | ||
|
||
export default usePatchBookCommentMutation; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
|
||
import type { APIBook, APIBookmarkedUserList } from '@/types/book'; | ||
import bookAPI from '@/apis/book'; | ||
import bookKeys from './key'; | ||
|
||
const updateBookmark = ({ | ||
bookId, | ||
newValue, | ||
}: { | ||
bookId: APIBook['bookId']; | ||
newValue: boolean; | ||
}) => { | ||
return newValue | ||
? bookAPI.addBookmark(bookId).then(({ data }) => data) | ||
: bookAPI.removeBookmark(bookId).then(({ data }) => data); | ||
}; | ||
|
||
const useUpdateBookmarkMutation = (bookId: APIBook['bookId']) => { | ||
const queryClient = useQueryClient(); | ||
const bookmarkQueryKey = bookKeys.bookmark(bookId); | ||
|
||
return useMutation({ | ||
mutationFn: (newValue: boolean) => updateBookmark({ bookId, newValue }), | ||
onMutate: async newValue => { | ||
await queryClient.cancelQueries({ queryKey: bookmarkQueryKey }); | ||
|
||
const previousData = | ||
queryClient.getQueryData<APIBookmarkedUserList>(bookmarkQueryKey); | ||
|
||
if (previousData) { | ||
// 낙관적 업데이트 | ||
queryClient.setQueryData<APIBookmarkedUserList>(bookmarkQueryKey, { | ||
...previousData, | ||
isInMyBookshelf: newValue, | ||
}); | ||
} | ||
|
||
return { previousData }; | ||
}, | ||
onError: (_err, _variables, context) => { | ||
if (!context || !context.previousData) { | ||
return; | ||
} | ||
|
||
queryClient.setQueryData<APIBookmarkedUserList>( | ||
bookmarkQueryKey, | ||
context.previousData | ||
); | ||
}, | ||
onSettled: () => { | ||
queryClient.invalidateQueries({ queryKey: bookmarkQueryKey }); | ||
}, | ||
}); | ||
}; | ||
|
||
export default useUpdateBookmarkMutation; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Link from 'next/link'; | ||
|
||
import { KAKAO_LOGIN_URL } from '@/constants/url'; | ||
import BottomActionButton from './BottomActionButton'; | ||
|
||
const LoginBottomActionButton = () => ( | ||
<Link href={KAKAO_LOGIN_URL}> | ||
<BottomActionButton>로그인 및 회원가입</BottomActionButton> | ||
</Link> | ||
); | ||
|
||
export default LoginBottomActionButton; |
Oops, something went wrong.