Repository navigation
feat : 구간 재생 준비 API 연동 #136
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
958fd9b
feat : 장소별 곡 좋아요 등록 API 연동
kim3360 1f772c0
fix : 위도 경도 하드코딩 값 수정
kim3360 3a2fc96
feat : 장소별 곡 좋아요 삭제 API 연동
kim3360 81ba3d1
feat : 장소별 곡 상세 조회 API 연동
kim3360 d141bdd
fix : keydown 이벤트 버블링 문제 수정
kim3360 09a0a14
feat : 구간 재생 준비 API 연동
kim3360 70edae5
fix : 곡 상세 백그라운드 크기 변경
kim3360 7c957e6
Merge branch 'develop' into feat/135-playback-preparations-api
kim3360 439ed3a
fix : 트랙 좋아요 낙관적업데이트 수정
kim3360 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,98 @@ | ||
| import type { QueryClient } from '@tanstack/react-query'; | ||
| import type { | ||
| GetLikedTracksResponse, | ||
| GetPlaceTrackDetailResponse, | ||
| GetPlaceTracksResponse, | ||
| } from '@/features/pin/types'; | ||
|
|
||
| type PlaceTrackQueriesSnapshot = [readonly unknown[], GetPlaceTracksResponse | undefined][]; | ||
| type LikedTrackQueriesSnapshot = [readonly unknown[], GetLikedTracksResponse | undefined][]; | ||
| type PlaceTrackDetailSnapshot = [readonly unknown[], GetPlaceTrackDetailResponse | undefined][]; | ||
|
|
||
| export type LikedTrackMutationContext = { | ||
| placeTrackQueries: PlaceTrackQueriesSnapshot; | ||
| likedTrackQueries: LikedTrackQueriesSnapshot; | ||
| placeTrackDetailQueries: PlaceTrackDetailSnapshot; | ||
| }; | ||
|
|
||
| export async function prepareLikedTrackMutation( | ||
| queryClient: QueryClient, | ||
| ): Promise<LikedTrackMutationContext> { | ||
| await Promise.all([ | ||
| queryClient.cancelQueries({ queryKey: ['pin', 'placeTrack'] }), | ||
| queryClient.cancelQueries({ queryKey: ['pin', 'likeTrack'] }), | ||
| queryClient.cancelQueries({ queryKey: ['pin', 'placeTrackDetail'] }), | ||
| ]); | ||
|
|
||
| return { | ||
| placeTrackQueries: queryClient.getQueriesData<GetPlaceTracksResponse>({ | ||
| queryKey: ['pin', 'placeTrack'], | ||
| }), | ||
| likedTrackQueries: queryClient.getQueriesData<GetLikedTracksResponse>({ | ||
| queryKey: ['pin', 'likeTrack'], | ||
| }), | ||
| placeTrackDetailQueries: queryClient.getQueriesData<GetPlaceTrackDetailResponse>({ | ||
| queryKey: ['pin', 'placeTrackDetail'], | ||
| }), | ||
| }; | ||
| } | ||
|
|
||
| export function rollbackLikedTrackMutation( | ||
| queryClient: QueryClient, | ||
| context?: LikedTrackMutationContext, | ||
| ) { | ||
| context?.placeTrackQueries.forEach(([queryKey, data]) => { | ||
| queryClient.setQueryData(queryKey, data); | ||
| }); | ||
| context?.likedTrackQueries.forEach(([queryKey, data]) => { | ||
| queryClient.setQueryData(queryKey, data); | ||
| }); | ||
| context?.placeTrackDetailQueries.forEach(([queryKey, data]) => { | ||
| queryClient.setQueryData(queryKey, data); | ||
| }); | ||
| } | ||
|
|
||
| export function setPlaceTrackLiked(queryClient: QueryClient, placeTrackId: string, liked: boolean) { | ||
| queryClient.setQueriesData<GetPlaceTracksResponse>({ queryKey: ['pin', 'placeTrack'] }, (old) => { | ||
| if (!old) return old; | ||
|
|
||
| return { | ||
| ...old, | ||
| tracks: old.tracks.map((track) => { | ||
| if (String(track.placeTrackId) !== placeTrackId) return track; | ||
| if (track.isLiked === liked) return track; | ||
|
|
||
| return { | ||
| ...track, | ||
| isLiked: liked, | ||
| likeCount: liked ? track.likeCount + 1 : Math.max(0, track.likeCount - 1), | ||
| }; | ||
| }), | ||
| }; | ||
| }); | ||
|
|
||
| queryClient.setQueryData<GetPlaceTrackDetailResponse>( | ||
| ['pin', 'placeTrackDetail', placeTrackId], | ||
| (old) => { | ||
| if (!old) return old; | ||
| if (old.userLike === liked) return old; | ||
|
|
||
| return { | ||
| ...old, | ||
| userLike: liked, | ||
| likeCount: liked ? old.likeCount + 1 : Math.max(0, old.likeCount - 1), | ||
| }; | ||
| }, | ||
| ); | ||
| } | ||
|
|
||
| export function removeLikedTrackFromList(queryClient: QueryClient, placeTrackId: string) { | ||
| queryClient.setQueriesData<GetLikedTracksResponse>({ queryKey: ['pin', 'likeTrack'] }, (old) => { | ||
| if (!old) return old; | ||
|
|
||
| return { | ||
| ...old, | ||
| tracks: old.tracks.filter((track) => String(track.placeTrackId) !== placeTrackId), | ||
| }; | ||
| }); | ||
| } | ||
This file contains hidden or 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,30 @@ | ||
| import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
| import { deleteLikedTracks } from '@/api/track'; | ||
| import { | ||
| prepareLikedTrackMutation, | ||
| removeLikedTrackFromList, | ||
| rollbackLikedTrackMutation, | ||
| setPlaceTrackLiked, | ||
| } from '@/features/pin/queries/likedTrackCache'; | ||
|
|
||
| export function useDeleteLikedTrack() { | ||
| const queryClient = useQueryClient(); | ||
|
|
||
| return useMutation({ | ||
| mutationFn: (placeTrackId: string) => deleteLikedTracks(placeTrackId), | ||
| onMutate: async (placeTrackId) => { | ||
| const context = await prepareLikedTrackMutation(queryClient); | ||
| setPlaceTrackLiked(queryClient, placeTrackId, false); | ||
| removeLikedTrackFromList(queryClient, placeTrackId); | ||
| return context; | ||
| }, | ||
| onError: (_error, _placeTrackId, context) => { | ||
| rollbackLikedTrackMutation(queryClient, context); | ||
| }, | ||
| onSettled: () => { | ||
| void queryClient.invalidateQueries({ queryKey: ['pin', 'likeTrack'] }); | ||
| void queryClient.invalidateQueries({ queryKey: ['pin', 'placeTrack'] }); | ||
| void queryClient.invalidateQueries({ queryKey: ['pin', 'placeTrackDetail'] }); | ||
| }, | ||
| }); | ||
| } |
This file contains hidden or 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,18 @@ | ||
| import { useQuery } from '@tanstack/react-query'; | ||
| import { getPlaybackPreparations } from '@/api/track'; | ||
|
|
||
| type UseGetPlaybackPreparationsParams = { | ||
| itunesTrackId?: string; | ||
| enabled?: boolean; | ||
| }; | ||
|
|
||
| export function useGetPlaybackPreparations({ | ||
| itunesTrackId, | ||
| enabled = true, | ||
| }: UseGetPlaybackPreparationsParams = {}) { | ||
| return useQuery({ | ||
| queryKey: ['pin', 'playbackPreparations', itunesTrackId], | ||
| queryFn: () => getPlaybackPreparations(itunesTrackId!), | ||
| enabled: enabled && Boolean(itunesTrackId), | ||
| }); | ||
| } |
This file contains hidden or 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 hidden or 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,18 @@ | ||
| import { useQuery } from '@tanstack/react-query'; | ||
| import { getPlaceTrackDetail } from '@/api/track'; | ||
|
|
||
| type UsePlaceTrackDetailParams = { | ||
| placeTrackId?: string; | ||
| enabled?: boolean; | ||
| }; | ||
|
|
||
| export function usePlaceTrackDetail({ | ||
| placeTrackId, | ||
| enabled = true, | ||
| }: UsePlaceTrackDetailParams = {}) { | ||
| return useQuery({ | ||
| queryKey: ['pin', 'placeTrackDetail', placeTrackId], | ||
| queryFn: () => getPlaceTrackDetail(placeTrackId!), | ||
| enabled: enabled && Boolean(placeTrackId), | ||
| }); | ||
| } |
This file contains hidden or 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,28 @@ | ||
| import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
| import { putLikedTracks } from '@/api/track'; | ||
| import { | ||
| prepareLikedTrackMutation, | ||
| rollbackLikedTrackMutation, | ||
| setPlaceTrackLiked, | ||
| } from '@/features/pin/queries/likedTrackCache'; | ||
|
|
||
| export function usePutLikedTrack() { | ||
| const queryClient = useQueryClient(); | ||
|
|
||
| return useMutation({ | ||
| mutationFn: (placeTrackId: string) => putLikedTracks(placeTrackId), | ||
| onMutate: async (placeTrackId) => { | ||
| const context = await prepareLikedTrackMutation(queryClient); | ||
| setPlaceTrackLiked(queryClient, placeTrackId, true); | ||
| return context; | ||
| }, | ||
| onError: (_error, _placeTrackId, context) => { | ||
| rollbackLikedTrackMutation(queryClient, context); | ||
| }, | ||
| onSettled: () => { | ||
| void queryClient.invalidateQueries({ queryKey: ['pin', 'likeTrack'] }); | ||
| void queryClient.invalidateQueries({ queryKey: ['pin', 'placeTrack'] }); | ||
| void queryClient.invalidateQueries({ queryKey: ['pin', 'placeTrackDetail'] }); | ||
| }, | ||
| }); | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.