2022-04-09 00:28:37 +08:00
|
|
|
import { fetchArtist } from '@/renderer/api/artist'
|
2022-04-16 21:14:03 +08:00
|
|
|
import { IpcChannels } from '@/shared/IpcChannels'
|
|
|
|
import { APIs } from '@/shared/CacheAPIs'
|
|
|
|
import {
|
2022-04-09 00:28:37 +08:00
|
|
|
FetchArtistParams,
|
2022-04-16 21:14:03 +08:00
|
|
|
ArtistApiNames,
|
2022-04-09 00:28:37 +08:00
|
|
|
FetchArtistResponse,
|
2022-04-16 21:14:03 +08:00
|
|
|
} from '@/shared/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
|
2022-03-30 00:53:05 +08:00
|
|
|
placeholderData: (): FetchArtistResponse =>
|
2022-04-09 00:28:37 +08:00
|
|
|
window.ipcRenderer?.sendSync(IpcChannels.GetApiCacheSync, {
|
2022-04-16 21:14:03 +08:00
|
|
|
api: APIs.Artist,
|
2022-03-30 00:53:05 +08:00
|
|
|
query: {
|
|
|
|
id: params.id,
|
|
|
|
},
|
|
|
|
}),
|
2022-03-13 14:40:38 +08:00
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|