mirror of
https://github.com/qier222/YesPlayMusic.git
synced 2025-03-01 06:07:25 +08:00
49 lines
1.2 KiB
TypeScript
49 lines
1.2 KiB
TypeScript
import { fetchLyric } from '@/web/api/track'
|
|
import reactQueryClient from '@/web/utils/reactQueryClient'
|
|
import {
|
|
FetchLyricParams,
|
|
FetchLyricResponse,
|
|
TrackApiNames,
|
|
} from '@/shared/api/Track'
|
|
import { APIs } from '@/shared/CacheAPIs'
|
|
import { IpcChannels } from '@/shared/IpcChannels'
|
|
import { useQuery } from 'react-query'
|
|
|
|
export default function useLyric(params: FetchLyricParams) {
|
|
return useQuery(
|
|
[TrackApiNames.FetchLyric, params],
|
|
() => {
|
|
return fetchLyric(params)
|
|
},
|
|
{
|
|
enabled: !!params.id && params.id !== 0,
|
|
refetchInterval: false,
|
|
refetchOnWindowFocus: false,
|
|
staleTime: Infinity,
|
|
initialData: (): FetchLyricResponse | undefined =>
|
|
window.ipcRenderer?.sendSync(IpcChannels.GetApiCacheSync, {
|
|
api: APIs.Lyric,
|
|
query: {
|
|
id: params.id,
|
|
},
|
|
}),
|
|
}
|
|
)
|
|
}
|
|
|
|
export function fetchTracksWithReactQuery(params: FetchLyricParams) {
|
|
return reactQueryClient.fetchQuery(
|
|
[TrackApiNames.FetchLyric, params],
|
|
() => {
|
|
return fetchLyric(params)
|
|
},
|
|
{
|
|
retry: 4,
|
|
retryDelay: (retryCount: number) => {
|
|
return retryCount * 500
|
|
},
|
|
staleTime: Infinity,
|
|
}
|
|
)
|
|
}
|