mirror of
https://github.com/qier222/YesPlayMusic.git
synced 2025-03-01 05:07:57 +08:00
29 lines
883 B
TypeScript
29 lines
883 B
TypeScript
import { fetchSimilarArtists } from '@/web/api/artist'
|
|
import { IpcChannels } from '@/shared/IpcChannels'
|
|
import { APIs } from '@/shared/CacheAPIs'
|
|
import {
|
|
FetchSimilarArtistsParams,
|
|
ArtistApiNames,
|
|
FetchSimilarArtistsResponse,
|
|
} from '@/shared/api/Artist'
|
|
import { useQuery } from '@tanstack/react-query'
|
|
|
|
export default function useSimilarArtists(params: FetchSimilarArtistsParams) {
|
|
return useQuery(
|
|
[ArtistApiNames.FetchSimilarArtists, params],
|
|
() => fetchSimilarArtists(params),
|
|
{
|
|
enabled: !!params.id && params.id > 0 && !isNaN(Number(params.id)),
|
|
staleTime: 5 * 60 * 1000, // 5 mins
|
|
retry: 0,
|
|
placeholderData: (): FetchSimilarArtistsResponse =>
|
|
window.ipcRenderer?.sendSync(IpcChannels.GetApiCacheSync, {
|
|
api: APIs.SimilarArtist,
|
|
query: {
|
|
id: params.id,
|
|
},
|
|
}),
|
|
}
|
|
)
|
|
}
|