feishin/src/renderer/index.tsx

70 lines
2.1 KiB
TypeScript
Raw Normal View History

import { Notifications } from '@mantine/notifications';
2023-08-04 01:41:45 -07:00
import {
PersistedClient,
Persister,
PersistQueryClientProvider,
} from '@tanstack/react-query-persist-client';
import { get, set, del } from 'idb-keyval';
2022-12-19 15:59:14 -08:00
import { createRoot } from 'react-dom/client';
import { App } from './app';
2022-12-31 19:26:58 -08:00
import { queryClient } from './lib/react-query';
2023-08-04 01:41:45 -07:00
import 'overlayscrollbars/overlayscrollbars.css';
2022-12-19 15:59:14 -08:00
2023-08-04 01:41:45 -07:00
export function createIDBPersister(idbValidKey: IDBValidKey = 'reactQuery') {
return {
persistClient: async (client: PersistedClient) => {
set(idbValidKey, client);
},
removeClient: async () => {
await del(idbValidKey);
},
restoreClient: async () => {
// eslint-disable-next-line no-return-await
return await get<PersistedClient>(idbValidKey);
},
} as Persister;
}
const indexedDbPersister = createIDBPersister('feishin');
2022-12-19 15:59:14 -08:00
const container = document.getElementById('root')! as HTMLElement;
const root = createRoot(container);
2022-12-31 19:26:58 -08:00
root.render(
2023-08-04 01:41:45 -07:00
<PersistQueryClientProvider
client={queryClient}
persistOptions={{
buster: 'feishin',
dehydrateOptions: {
dehydrateQueries: true,
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: {
cacheTime: Infinity,
},
},
},
maxAge: Infinity,
persister: indexedDbPersister,
}}
>
2023-07-01 19:10:05 -07:00
<Notifications
containerWidth="300px"
position="bottom-center"
zIndex={5}
2023-07-01 19:10:05 -07:00
/>
<App />
2023-08-04 01:41:45 -07:00
</PersistQueryClientProvider>,
2022-12-31 19:26:58 -08:00
);