a few additional persisters edits

This commit is contained in:
Nate Kelley 2025-08-15 15:48:39 -06:00
parent 7e5344ccc6
commit 1855adf285
No known key found for this signature in database
GPG Key ID: FD90372AB8D98B4F
5 changed files with 17 additions and 8 deletions

View File

@ -9,11 +9,10 @@ import {
} from './requests';
export const useGetUserFavorites = () => {
const queryFn = async () => getUserFavorites();
const organizationId = useGetUserOrganizationId();
return useQuery({
...userQueryKeys.favoritesGetList,
queryFn,
queryFn: getUserFavorites,
enabled: !!organizationId,
});
};
@ -22,7 +21,7 @@ export const prefetchGetUserFavorites = async (queryClientProp?: QueryClient) =>
const queryClient = queryClientProp || new QueryClient();
await queryClient.prefetchQuery({
...userQueryKeys.favoritesGetList,
queryFn: () => getUserFavorites(),
queryFn: getUserFavorites,
});
return queryClient;
};

View File

@ -1,4 +1,4 @@
import { isServer, type QueryClient, QueryClientProvider } from '@tanstack/react-query';
import type { QueryClient } from '@tanstack/react-query';
import { PersistQueryClientProvider as TanstackPersistQueryClientProvider } from '@tanstack/react-query-persist-client';
import React from 'react';
import { persistOptions } from '@/integrations/tanstack-query/create-persister';
@ -13,15 +13,20 @@ export const QueryPersister = ({
}) => {
const [mounted, setMounted] = React.useState(false);
console.log(queryClient.getQueryData(userQueryKeys.favoritesGetList.queryKey));
return (
<TanstackPersistQueryClientProvider
client={queryClient}
persistOptions={persistOptions}
onSuccess={() => {
setMounted(true);
queryClient.resumePausedMutations();
console.log('onSuccess', queryClient.getQueryData(userQueryKeys.favoritesGetList.queryKey));
}}
>
{mounted ? children : null}
{/* {mounted ? children : null} */}
{children}
</TanstackPersistQueryClientProvider>
);
};

View File

@ -4,11 +4,15 @@ import { hashKey, isServer } from '@tanstack/react-query';
import type { PersistQueryClientProviderProps } from '@tanstack/react-query-persist-client';
import { dictionariesQueryKeys } from '@/api/query_keys/dictionaries';
import { slackQueryKeys } from '@/api/query_keys/slack';
import { userQueryKeys } from '@/api/query_keys/users';
import packageJson from '../../../package.json';
const buster = packageJson.version;
export const PERSIST_TIME = 1000 * 60 * 60 * 24 * 3; // 3 days
const PERSISTED_QUERIES = [slackQueryKeys.slackGetChannels.queryKey].map(hashKey);
const PERSISTED_QUERIES = [
slackQueryKeys.slackGetChannels.queryKey,
userQueryKeys.favoritesGetList.queryKey,
].map(hashKey);
export const PERMANENT_QUERIES = [
dictionariesQueryKeys.getCurrencies.queryKey,
@ -30,7 +34,6 @@ const persisterAsync = createAsyncStoragePersister({
for (const query of client.clientState.queries) {
const isPermanentQuery = PERMANENT_QUERIES.includes(query.queryHash);
if (!isPermanentQuery) {
console.log('setting dataUpdatedAt to 1', query.queryHash);
query.state.dataUpdatedAt = 1;
}
}
@ -44,7 +47,6 @@ export const persistOptions: PersistQueryClientProviderProps['persistOptions'] =
shouldDehydrateQuery: (query) => {
const isList =
query.queryKey[1] === 'list' || query.queryKey[query.queryKey.length - 1] === 'list';
return isList || ALL_PERSISTED_QUERIES.includes(query.queryHash);
},
},

View File

@ -22,6 +22,7 @@ export const createRouter = () => {
context: { queryClient, user: null }, //context is defined in the root route
scrollRestoration: true,
defaultPreload: 'intent',
defaultPendingComponent: () => <div>Loading...</div>,
Wrap: (props) => {
return (
<TanstackQuery.Provider queryClient={queryClient}>

View File

@ -1,4 +1,5 @@
import { createFileRoute, Outlet, redirect } from '@tanstack/react-router';
import { prefetchGetUserFavorites } from '@/api/buster_rest/users/favorites/queryRequests';
import { prefetchGetMyUserInfo } from '@/api/buster_rest/users/queryRequests';
import { getAppLayout } from '@/api/server-functions/getAppLayout';
import { AppProviders } from '@/context/Providers';
@ -23,6 +24,7 @@ export const Route = createFileRoute('/app')({
const [initialLayout] = await Promise.all([
getAppLayout({ data: { id: PRIMARY_APP_LAYOUT_ID } }),
prefetchGetMyUserInfo(queryClient),
prefetchGetUserFavorites(queryClient),
]);
return {
initialLayout,