Don't load onSnapshot from cache in hook listen for contract (could help 404 errors?)

This commit is contained in:
jahooma 2022-01-29 23:05:32 -06:00
parent 967ac1b08d
commit ac9af1acd6
2 changed files with 4 additions and 4 deletions

View File

@ -17,7 +17,7 @@ import {
import _ from 'lodash'
import { app } from './init'
import { getValues, listenForValues } from './utils'
import { getValues, listenForValue, listenForValues } from './utils'
import { Contract } from '../../../common/contract'
import { getProbability } from '../../../common/calculate'
import { createRNG, shuffle } from '../../../common/util/random'
@ -125,9 +125,7 @@ export function listenForContract(
setContract: (contract: Contract | null) => void
) {
const contractRef = doc(contractCollection, contractId)
return onSnapshot(contractRef, (contractSnap) => {
setContract((contractSnap.data() ?? null) as Contract | null)
})
return listenForValue<Contract>(contractRef, setContract)
}
function chooseRandomSubset(contracts: Contract[], count: number) {

View File

@ -23,6 +23,8 @@ export function listenForValue<T>(
setValue: (value: T | null) => void
) {
return onSnapshot(docRef, (snapshot) => {
if (snapshot.metadata.fromCache) return
const value = snapshot.exists() ? (snapshot.data() as T) : null
setValue(value)
})