2022-07-12 22:42:50 +08:00
|
|
|
import { AppleMusicArtist } from '@/shared/AppleMusic'
|
|
|
|
import { APIs } from '@/shared/CacheAPIs'
|
|
|
|
import { IpcChannels } from '@/shared/IpcChannels'
|
2022-08-03 23:48:39 +08:00
|
|
|
import { useQuery } from '@tanstack/react-query'
|
2022-07-12 22:42:50 +08:00
|
|
|
|
|
|
|
export default function useAppleMusicArtist(props: {
|
|
|
|
id?: number
|
|
|
|
name?: string
|
|
|
|
}) {
|
|
|
|
const { id, name } = props
|
|
|
|
return useQuery(
|
|
|
|
['useAppleMusicArtist', props],
|
|
|
|
async () => {
|
|
|
|
if (!id || !name) return
|
2022-10-28 20:29:04 +08:00
|
|
|
|
|
|
|
const cache = await window.ipcRenderer?.invoke(IpcChannels.GetApiCache, {
|
|
|
|
api: APIs.AppleMusicArtist,
|
|
|
|
query: {
|
|
|
|
id,
|
|
|
|
},
|
|
|
|
})
|
|
|
|
|
|
|
|
if (cache) return cache
|
|
|
|
|
2022-07-12 22:42:50 +08:00
|
|
|
return window.ipcRenderer?.invoke(IpcChannels.GetArtistFromAppleMusic, {
|
|
|
|
id,
|
|
|
|
name,
|
|
|
|
})
|
|
|
|
},
|
|
|
|
{
|
|
|
|
enabled: !!id && !!name,
|
|
|
|
refetchOnWindowFocus: false,
|
|
|
|
refetchInterval: false,
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|