mirror of
https://github.com/qier222/YesPlayMusic.git
synced 2024-12-12 04:04:02 +08:00
34 lines
853 B
TypeScript
34 lines
853 B
TypeScript
|
import { AppleMusicArtist } from '@/shared/AppleMusic'
|
||
|
import { APIs } from '@/shared/CacheAPIs'
|
||
|
import { IpcChannels } from '@/shared/IpcChannels'
|
||
|
import { useQuery } from 'react-query'
|
||
|
|
||
|
export default function useAppleMusicArtist(props: {
|
||
|
id?: number
|
||
|
name?: string
|
||
|
}) {
|
||
|
const { id, name } = props
|
||
|
return useQuery(
|
||
|
['useAppleMusicArtist', props],
|
||
|
async () => {
|
||
|
if (!id || !name) return
|
||
|
return window.ipcRenderer?.invoke(IpcChannels.GetArtistFromAppleMusic, {
|
||
|
id,
|
||
|
name,
|
||
|
})
|
||
|
},
|
||
|
{
|
||
|
enabled: !!id && !!name,
|
||
|
refetchOnWindowFocus: false,
|
||
|
refetchInterval: false,
|
||
|
initialData: (): AppleMusicArtist =>
|
||
|
window.ipcRenderer?.sendSync(IpcChannels.GetApiCacheSync, {
|
||
|
api: APIs.AppleMusicArtist,
|
||
|
query: {
|
||
|
id,
|
||
|
},
|
||
|
}),
|
||
|
}
|
||
|
)
|
||
|
}
|