Merge branch 'manifoldmarkets:main' into main

This commit is contained in:
marsteralex 2022-09-08 19:56:45 -07:00 committed by GitHub
commit d342de83e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 7 deletions

View File

@ -13,6 +13,7 @@ import {
getUserBetContractsQuery, getUserBetContractsQuery,
} from 'web/lib/firebase/contracts' } from 'web/lib/firebase/contracts'
import { useQueryClient } from 'react-query' import { useQueryClient } from 'react-query'
import { MINUTE_MS } from 'common/util/time'
export const useContracts = () => { export const useContracts = () => {
const [contracts, setContracts] = useState<Contract[] | undefined>() const [contracts, setContracts] = useState<Contract[] | undefined>()
@ -96,8 +97,10 @@ export const useUpdatedContracts = (contracts: Contract[] | undefined) => {
export const usePrefetchUserBetContracts = (userId: string) => { export const usePrefetchUserBetContracts = (userId: string) => {
const queryClient = useQueryClient() const queryClient = useQueryClient()
return queryClient.prefetchQuery(['contracts', 'bets', userId], () => return queryClient.prefetchQuery(
getUserBetContracts(userId) ['contracts', 'bets', userId],
() => getUserBetContracts(userId),
{ staleTime: 5 * MINUTE_MS }
) )
} }

View File

@ -1,6 +1,6 @@
import { useQueryClient } from 'react-query' import { useQueryClient } from 'react-query'
import { useFirestoreQueryData } from '@react-query-firebase/firestore' import { useFirestoreQueryData } from '@react-query-firebase/firestore'
import { DAY_MS, HOUR_MS } from 'common/util/time' import { DAY_MS, HOUR_MS, MINUTE_MS } from 'common/util/time'
import { import {
getPortfolioHistory, getPortfolioHistory,
getPortfolioHistoryQuery, getPortfolioHistoryQuery,
@ -15,8 +15,10 @@ const getCutoff = (period: Period) => {
export const usePrefetchPortfolioHistory = (userId: string, period: Period) => { export const usePrefetchPortfolioHistory = (userId: string, period: Period) => {
const queryClient = useQueryClient() const queryClient = useQueryClient()
const cutoff = getCutoff(period) const cutoff = getCutoff(period)
return queryClient.prefetchQuery(['portfolio-history', userId, cutoff], () => return queryClient.prefetchQuery(
getPortfolioHistory(userId, cutoff) ['portfolio-history', userId, cutoff],
() => getPortfolioHistory(userId, cutoff),
{ staleTime: 15 * MINUTE_MS }
) )
} }
@ -24,7 +26,9 @@ export const usePortfolioHistory = (userId: string, period: Period) => {
const cutoff = getCutoff(period) const cutoff = getCutoff(period)
const result = useFirestoreQueryData( const result = useFirestoreQueryData(
['portfolio-history', userId, cutoff], ['portfolio-history', userId, cutoff],
getPortfolioHistoryQuery(userId, cutoff) getPortfolioHistoryQuery(userId, cutoff),
{},
{ staleTime: 15 * MINUTE_MS }
) )
return result.data return result.data
} }

View File

@ -7,10 +7,15 @@ import {
getUserBetsQuery, getUserBetsQuery,
listenForUserContractBets, listenForUserContractBets,
} from 'web/lib/firebase/bets' } from 'web/lib/firebase/bets'
import { MINUTE_MS } from 'common/util/time'
export const usePrefetchUserBets = (userId: string) => { export const usePrefetchUserBets = (userId: string) => {
const queryClient = useQueryClient() const queryClient = useQueryClient()
return queryClient.prefetchQuery(['bets', userId], () => getUserBets(userId)) return queryClient.prefetchQuery(
['bets', userId],
() => getUserBets(userId),
{ staleTime: MINUTE_MS }
)
} }
export const useUserBets = (userId: string) => { export const useUserBets = (userId: string) => {