Prefetch daily movers

This commit is contained in:
James Grugett 2022-09-16 16:35:03 -05:00
parent 70ef9e1836
commit 1321139e7f
2 changed files with 21 additions and 0 deletions

View File

@ -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),
])
}

View File

@ -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 }
)
}
}