25 lines
716 B
TypeScript
Raw Normal View History

2022-03-13 14:40:38 +08:00
import { fetchArtist } from '@/api/artist'
import { ArtistApiNames } from '@/api/artist'
2022-03-23 01:21:22 +08:00
import type { FetchArtistParams, FetchArtistResponse } from '@/api/artist'
2022-03-13 14:40:38 +08:00
2022-03-23 01:21:22 +08:00
export default function useArtist(
params: FetchArtistParams,
noCache?: boolean
) {
2022-03-13 14:40:38 +08:00
return useQuery(
[ArtistApiNames.FETCH_ARTIST, params],
2022-03-23 01:21:22 +08:00
() => fetchArtist(params, !!noCache),
2022-03-13 14:40:38 +08:00
{
enabled: !!params.id && params.id > 0 && !isNaN(Number(params.id)),
2022-03-23 01:21:22 +08:00
staleTime: 5 * 60 * 1000, // 5 mins
// placeholderData: (): FetchArtistResponse =>
// window.ipcRenderer.sendSync('getApiCacheSync', {
// api: 'artists',
// query: {
// id: params.id,
// },
// }),
2022-03-13 14:40:38 +08:00
}
)
}