mirror of
https://github.com/qier222/YesPlayMusic.git
synced 2025-03-01 05:24:26 +08:00
40 lines
1.0 KiB
TypeScript
40 lines
1.0 KiB
TypeScript
import { fetchArtist } from '@/web/api/artist'
|
|
import { IpcChannels } from '@/shared/IpcChannels'
|
|
import { APIs } from '@/shared/CacheAPIs'
|
|
import { ArtistApiNames } from '@/shared/api/Artist'
|
|
import { useQuery } from '@tanstack/react-query'
|
|
import reactQueryClient from '@/web/utils/reactQueryClient'
|
|
|
|
export default function useArtists(ids: number[]) {
|
|
return useQuery(
|
|
['fetchArtists', ids],
|
|
() =>
|
|
Promise.all(
|
|
ids.map(async id => {
|
|
const queryData = reactQueryClient.getQueryData([
|
|
ArtistApiNames.FetchArtist,
|
|
{ id },
|
|
])
|
|
if (queryData) return queryData
|
|
|
|
const cache = await window.ipcRenderer?.invoke(
|
|
IpcChannels.GetApiCache,
|
|
{
|
|
api: APIs.Artist,
|
|
query: {
|
|
id,
|
|
},
|
|
}
|
|
)
|
|
if (cache) return cache
|
|
|
|
return fetchArtist({ id })
|
|
})
|
|
),
|
|
{
|
|
enabled: !!ids && ids.length > 0,
|
|
staleTime: 5 * 60 * 1000, // 5 mins
|
|
}
|
|
)
|
|
}
|