feat: updates

This commit is contained in:
qier222 2022-10-28 20:29:04 +08:00
parent a1b0bcf4d3
commit 884f3df41a
No known key found for this signature in database
198 changed files with 4572 additions and 5336 deletions

View file

@ -14,20 +14,23 @@ import { useQuery } from '@tanstack/react-query'
export default function useTracks(params: FetchTracksParams) {
return useQuery(
[TrackApiNames.FetchTracks, params],
() => {
async () => {
// fetch from cache as initial data
const cache = await window.ipcRenderer?.invoke(IpcChannels.GetApiCache, {
api: APIs.Track,
query: {
ids: params.ids.join(','),
},
})
if (cache) return cache
return fetchTracks(params)
},
{
enabled: params.ids.length !== 0,
refetchInterval: false,
refetchOnWindowFocus: false,
staleTime: Infinity,
initialData: (): FetchTracksResponse | undefined =>
window.ipcRenderer?.sendSync(IpcChannels.GetApiCacheSync, {
api: APIs.Track,
query: {
ids: params.ids.join(','),
},
}),
}
)
}
@ -35,7 +38,14 @@ export default function useTracks(params: FetchTracksParams) {
export function fetchTracksWithReactQuery(params: FetchTracksParams) {
return reactQueryClient.fetchQuery(
[TrackApiNames.FetchTracks, params],
() => {
async () => {
const cache = await window.ipcRenderer?.invoke(IpcChannels.GetApiCache, {
api: APIs.Track,
query: {
ids: params.ids.join(','),
},
})
if (cache) return cache as FetchTracksResponse
return fetchTracks(params)
},
{