-
Notifications
You must be signed in to change notification settings - Fork 2
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
* config: react-query, devtools 설치 * feat: 쿼리프로바이더, 데브 툴 적용 * refactor: 양방향 스와이프 로직 React Query 적용 1. useQuery, useInfiteQuery hook으로 기존 extraFetch hook 대체 2. entries api 응답값의 prev, next 사용하지 않게 되었음. * refactor: 코멘트 작성 로직 React Query 적용 1. useQuery, useMutation hook으로 기존 로직 대체 2. remote 함수 인자타입 변경 - mutateFn의 함수는 인자를 1개로 제한 3. onSuccess는 useMutation 과 mutate 함수 순서로 실행됨 * test: 댓글 mock 핸들러 수정
- Loading branch information
1 parent
7a7d161
commit 3745893
Showing
12 changed files
with
245 additions
and
84 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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,24 @@ | ||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; | ||
import { getComments, postComment } from '../remotes/comments'; | ||
|
||
export const useCommentsQuery = (songId: number, partId: number) => { | ||
const { data: comments, ...queries } = useQuery({ | ||
queryKey: ['comments', songId, partId], | ||
queryFn: () => getComments(songId, partId), | ||
}); | ||
|
||
return { comments, queries }; | ||
}; | ||
|
||
export const usePostCommentMutation = () => { | ||
const client = useQueryClient(); | ||
|
||
const { mutate: postNewComment, ...mutations } = useMutation({ | ||
mutationFn: postComment, | ||
onSuccess: (_, { songId, partId }) => { | ||
client.invalidateQueries({ queryKey: ['comments', songId, partId] }); | ||
}, | ||
}); | ||
|
||
return { postNewComment, mutations }; | ||
}; |
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 |
---|---|---|
@@ -1,21 +1,21 @@ | ||
import { useCallback } from 'react'; | ||
import useFetch from '@/shared/hooks/useFetch'; | ||
import useValidParams from '@/shared/hooks/useValidParams'; | ||
import { getSongDetailEntries } from '../remotes/songs'; | ||
import { useSongDetailEntriesQuery } from '../queries'; | ||
import type { Genre } from '../types/Song.type'; | ||
|
||
const useSongDetailEntries = () => { | ||
const { id: songIdParams, genre: genreParams } = useValidParams(); | ||
|
||
const { data: songDetailEntries } = useFetch(() => | ||
getSongDetailEntries(Number(songIdParams), genreParams as Genre) | ||
); | ||
const { | ||
songDetailEntries, | ||
queries: { isLoading: isLoadingSongDetailEntries }, | ||
} = useSongDetailEntriesQuery(Number(songIdParams), genreParams as Genre); | ||
|
||
const scrollIntoCurrentSong: React.RefCallback<HTMLDivElement> = useCallback((dom) => { | ||
if (dom !== null) dom.scrollIntoView({ behavior: 'instant', block: 'start' }); | ||
}, []); | ||
|
||
return { songDetailEntries, scrollIntoCurrentSong }; | ||
return { songDetailEntries, isLoadingSongDetailEntries, scrollIntoCurrentSong }; | ||
}; | ||
|
||
export default useSongDetailEntries; |
Oops, something went wrong.