mirror of
https://github.com/qier222/YesPlayMusic.git
synced 2025-03-01 05:42:34 +08:00
36 lines
1.1 KiB
TypeScript
36 lines
1.1 KiB
TypeScript
import { fetchSimilarArtists } from '@/web/api/artist'
|
|
import { IpcChannels } from '@/shared/IpcChannels'
|
|
import { CacheAPIs } from '@/shared/CacheAPIs'
|
|
import { FetchSimilarArtistsParams, ArtistApiNames } from '@/shared/api/Artist'
|
|
import { useQuery } from '@tanstack/react-query'
|
|
import reactQueryClient from '@/web/utils/reactQueryClient'
|
|
|
|
export default function useSimilarArtists(params: FetchSimilarArtistsParams) {
|
|
const key = [ArtistApiNames.FetchSimilarArtists, params]
|
|
return useQuery(
|
|
key,
|
|
() => {
|
|
window.ipcRenderer
|
|
?.invoke(IpcChannels.GetApiCache, {
|
|
api: CacheAPIs.SimilarArtist,
|
|
query: {
|
|
id: params.id,
|
|
},
|
|
})
|
|
.then(cache => {
|
|
const existsQueryData = reactQueryClient.getQueryData(key)
|
|
if (!existsQueryData && cache) {
|
|
reactQueryClient.setQueryData(key, cache)
|
|
}
|
|
})
|
|
|
|
return fetchSimilarArtists(params)
|
|
},
|
|
{
|
|
enabled: !!params.id && params.id > 0 && !isNaN(Number(params.id)),
|
|
staleTime: 5 * 60 * 1000, // 5 mins
|
|
retry: 0,
|
|
}
|
|
)
|
|
}
|