-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
236 additions
and
191 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { spotifySearch, youtubeSearch } from '../api/fetchMusicList'; | ||
import { MusicItem } from '../model/type'; | ||
|
||
// TODO - 쿼리 유효성 검사 / 훅이 여러번 실행되는 문제 해결 | ||
|
||
/** | ||
* 검색 훅 | ||
* @param query | ||
* @returns | ||
*/ | ||
export const useMusicSearch = (query: string) => { | ||
const spotifyQuery = useQuery({ | ||
queryKey: ['spotify', query], | ||
queryFn: () => spotifySearch(query), | ||
enabled: !!query, | ||
staleTime: 1000 * 60 * 5, // 5분 | ||
gcTime: 1000 * 60 * 30, // 30분 | ||
refetchOnWindowFocus: false, // 윈도우 포커스 할 때 자동 리패치 옵션 제거 | ||
retry: 1 // 1회 재시도 | ||
}); | ||
|
||
const youtubeQuery = useQuery({ | ||
queryKey: [ | ||
'youtube', | ||
spotifyQuery.data?.name, | ||
spotifyQuery.data?.artists[0].name | ||
], | ||
queryFn: () => | ||
youtubeSearch({ | ||
trackName: spotifyQuery.data!.name, | ||
artistName: spotifyQuery.data!.artists[0].name | ||
}), | ||
enabled: | ||
!!spotifyQuery.data?.name && | ||
!!spotifyQuery.data?.artists?.[0]?.name, | ||
staleTime: 1000 * 60 * 5, // 5분 | ||
gcTime: 1000 * 60 * 30, // 30분 | ||
refetchOnWindowFocus: false, // 윈도우 포커스 할 때 자동 리패치 옵션 제거 | ||
retry: 1 // 1회 재시도 | ||
}); | ||
|
||
const combinedData = | ||
spotifyQuery.data && youtubeQuery.data | ||
? { | ||
title: spotifyQuery.data?.name, | ||
artist: spotifyQuery.data?.artists[0].name, | ||
thumbnailUrl: spotifyQuery.data?.album.images[0].url, | ||
// youtubeId: 'M5aEiDSx7kI' // api 호출 제한 상황용 테스트 ID | ||
youtubeId: youtubeQuery.data | ||
} | ||
: undefined; | ||
|
||
return { | ||
data: combinedData as MusicItem, | ||
isLoading: spotifyQuery.isLoading || youtubeQuery.isLoading, | ||
error: spotifyQuery.error || youtubeQuery.error, | ||
spotifyStatus: spotifyQuery.status, | ||
youtubeStatus: youtubeQuery.status | ||
}; | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
export { MusicCard } from './ui/MusicCard'; | ||
export { EmptyMusicCard } from './ui/EmptyMusicCard'; | ||
// export { useSearchMusic } from './hooks/useSearchMusic'; | ||
export { searchMusic } from './api/fetchMusicList'; | ||
export { useMusicSearch } from './hooks/useMusicSearch'; |
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,4 +1,5 @@ | ||
export { VisibilityButton } from './visibility/ui/VisibilityButton'; | ||
export { MusicCardList } from '@/features/diary-write/musicList/ui/MusicCardList'; | ||
export { ConditionButtonGroup } from './condition/ui/ConditionButtonGroup'; | ||
export { SearchModeButtonGroup } from './search-mode-selector/ui/SearchModeButtonGroup'; | ||
export { MusicSearchInput } from './music-search-input/ui/MusicSearchInput'; |
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
Oops, something went wrong.