mirror of
https://github.com/GiriNeko/YesPlayMusic.git
synced 2025-12-18 06:07:48 +00:00
chore: 用esbuild代替vite来打包main
This commit is contained in:
parent
b4590c3c34
commit
c4219afd3d
152 changed files with 669 additions and 747 deletions
39
src/renderer/hooks/usePlaylist.ts
Normal file
39
src/renderer/hooks/usePlaylist.ts
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import { fetchPlaylist } from '@/api/playlist'
|
||||
import { PlaylistApiNames } from '@/api/playlist'
|
||||
import type { FetchPlaylistParams, FetchPlaylistResponse } 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))),
|
||||
refetchOnWindowFocus: true,
|
||||
// placeholderData: (): FetchPlaylistResponse | undefined =>
|
||||
// window.ipcRenderer.sendSync('getApiCacheSync', {
|
||||
// api: 'playlist/detail',
|
||||
// query: {
|
||||
// id: params.id,
|
||||
// },
|
||||
// }),
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
export async function prefetchPlaylist(params: FetchPlaylistParams) {
|
||||
await reactQueryClient.prefetchQuery(
|
||||
[PlaylistApiNames.FETCH_PLAYLIST, params],
|
||||
() => fetch(params),
|
||||
{
|
||||
staleTime: 3600000,
|
||||
}
|
||||
)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue