mirror of
https://github.com/antebudimir/feishin.git
synced 2025-12-31 10:03:33 +00:00
57 lines
1.7 KiB
TypeScript
57 lines
1.7 KiB
TypeScript
import {
|
|
PersistedClient,
|
|
Persister,
|
|
PersistQueryClientProvider,
|
|
} from '@tanstack/react-query-persist-client';
|
|
import { del, get, set } from 'idb-keyval';
|
|
import { createRoot } from 'react-dom/client';
|
|
|
|
import { App } from '/@/renderer/app';
|
|
import { queryClient } from '/@/renderer/lib/react-query';
|
|
|
|
function createIDBPersister(idbValidKey: IDBValidKey = 'reactQuery') {
|
|
return {
|
|
persistClient: async (client: PersistedClient) => {
|
|
set(idbValidKey, client);
|
|
},
|
|
removeClient: async () => {
|
|
await del(idbValidKey);
|
|
},
|
|
restoreClient: async () => {
|
|
return await get<PersistedClient>(idbValidKey);
|
|
},
|
|
} as Persister;
|
|
}
|
|
|
|
const indexedDbPersister = createIDBPersister('feishin');
|
|
|
|
createRoot(document.getElementById('root')!).render(
|
|
<PersistQueryClientProvider
|
|
client={queryClient}
|
|
persistOptions={{
|
|
buster: 'feishin',
|
|
dehydrateOptions: {
|
|
shouldDehydrateQuery: (query) => {
|
|
const isSuccess = query.state.status === 'success';
|
|
const isLyricsQueryKey =
|
|
query.queryKey.includes('song') &&
|
|
query.queryKey.includes('lyrics') &&
|
|
query.queryKey.includes('select');
|
|
|
|
return isSuccess && isLyricsQueryKey;
|
|
},
|
|
},
|
|
hydrateOptions: {
|
|
defaultOptions: {
|
|
queries: {
|
|
gcTime: Infinity,
|
|
},
|
|
},
|
|
},
|
|
maxAge: Infinity,
|
|
persister: indexedDbPersister,
|
|
}}
|
|
>
|
|
<App />
|
|
</PersistQueryClientProvider>,
|
|
);
|