diff --git a/web/hooks/use-prefetch.ts b/web/hooks/use-prefetch.ts index 46d78b3c..5d95baf4 100644 --- a/web/hooks/use-prefetch.ts +++ b/web/hooks/use-prefetch.ts @@ -1,5 +1,6 @@ import { usePrefetchUserBetContracts } from './use-contracts' import { usePrefetchPortfolioHistory } from './use-portfolio-history' +import { usePrefetchProbChanges } from './use-prob-changes' import { usePrefetchUserBets } from './use-user-bets' export function usePrefetch(userId: string | undefined) { @@ -8,5 +9,6 @@ export function usePrefetch(userId: string | undefined) { usePrefetchUserBets(maybeUserId), usePrefetchUserBetContracts(maybeUserId), usePrefetchPortfolioHistory(maybeUserId, 'weekly'), + usePrefetchProbChanges(userId), ]) } diff --git a/web/hooks/use-prob-changes.tsx b/web/hooks/use-prob-changes.tsx index c5e2c9bd..699b67ee 100644 --- a/web/hooks/use-prob-changes.tsx +++ b/web/hooks/use-prob-changes.tsx @@ -1,8 +1,11 @@ import { useFirestoreQueryData } from '@react-query-firebase/firestore' +import { MINUTE_MS } from 'common/util/time' +import { useQueryClient } from 'react-query' import { getProbChangesNegative, getProbChangesPositive, } from 'web/lib/firebase/contracts' +import { getValues } from 'web/lib/firebase/utils' export const useProbChanges = (userId: string) => { const { data: positiveChanges } = useFirestoreQueryData( @@ -20,3 +23,19 @@ export const useProbChanges = (userId: string) => { return { positiveChanges, negativeChanges } } + +export const usePrefetchProbChanges = (userId: string | undefined) => { + const queryClient = useQueryClient() + if (userId) { + queryClient.prefetchQuery( + ['prob-changes-day-positive', userId], + () => getValues(getProbChangesPositive(userId)), + { staleTime: MINUTE_MS } + ) + queryClient.prefetchQuery( + ['prob-changes-day-negative', userId], + () => getValues(getProbChangesNegative(userId)), + { staleTime: MINUTE_MS } + ) + } +}