mirror of
https://github.com/qier222/YesPlayMusic.git
synced 2025-03-01 09:24:10 +08:00
34 lines
903 B
TypeScript
34 lines
903 B
TypeScript
![]() |
import { fetchPlaylist } from '@/api/playlist'
|
||
|
import { PlaylistApiNames } from '@/api/playlist'
|
||
|
import type { FetchPlaylistParams } from '@/api/playlist'
|
||
|
import reactQueryClient from '@/utils/reactQueryClient'
|
||
|
|
||
|
const fetch = (params: FetchPlaylistParams, noCache?: boolean) => {
|
||
|
return fetchPlaylist(params, !!noCache)
|
||
|
}
|
||
|
|
||
|
export default function usePlaylist(
|
||
|
params: FetchPlaylistParams,
|
||
|
noCache?: boolean
|
||
|
) {
|
||
|
return useQuery(
|
||
|
[PlaylistApiNames.FETCH_PLAYLIST, params],
|
||
|
() => fetch(params, noCache),
|
||
|
{
|
||
|
enabled: !!(params.id && params.id > 0 && !isNaN(Number(params.id))),
|
||
|
staleTime: 3600000,
|
||
|
}
|
||
|
)
|
||
|
}
|
||
|
|
||
|
export async function prefetchPlaylist(params: FetchPlaylistParams) {
|
||
|
console.log('prefetchAlbum', params)
|
||
|
await reactQueryClient.prefetchQuery(
|
||
|
[PlaylistApiNames.FETCH_PLAYLIST, params],
|
||
|
() => fetch(params),
|
||
|
{
|
||
|
staleTime: 3600000,
|
||
|
}
|
||
|
)
|
||
|
}
|