Make feed auto-update again.

This commit is contained in:
James Grugett 2022-02-20 21:06:10 -06:00
parent 20a3966820
commit 7c18f4b96b
3 changed files with 22 additions and 5 deletions

View File

@ -8,7 +8,9 @@ import { Comment, getRecentComments } from '../lib/firebase/comments'
import { Contract, listAllContracts } from '../lib/firebase/contracts' import { Contract, listAllContracts } from '../lib/firebase/contracts'
import { listAllFolds } from '../lib/firebase/folds' import { listAllFolds } from '../lib/firebase/folds'
import { findActiveContracts } from '../pages/activity' import { findActiveContracts } from '../pages/activity'
import { useUpdatedContracts } from './use-contracts' import { useRecentBets } from './use-bets'
import { useRecentComments } from './use-comments'
import { useContracts } from './use-contracts'
import { useFollowedFolds } from './use-fold' import { useFollowedFolds } from './use-fold'
import { useUserBetContracts } from './use-user-bets' import { useUserBetContracts } from './use-user-bets'
@ -36,7 +38,9 @@ export const useActiveContracts = (
}, },
user: User | undefined | null user: User | undefined | null
) => { ) => {
const contracts = useUpdatedContracts(props.contracts) const contracts = useContracts() ?? props.contracts
const recentBets = useRecentBets() ?? props.recentBets
const recentComments = useRecentComments() ?? props.recentComments
const followedFoldIds = useFollowedFolds(user) const followedFoldIds = useFollowedFolds(user)
@ -71,8 +75,6 @@ export const useActiveContracts = (
) )
} }
const { recentComments, recentBets } = props
const activeContracts = findActiveContracts( const activeContracts = findActiveContracts(
feedContracts, feedContracts,
recentComments, recentComments,

View File

@ -1,6 +1,11 @@
import { useEffect, useState } from 'react' import { useEffect, useState } from 'react'
import { Contract } from '../../common/contract' import { Contract } from '../../common/contract'
import { Bet, listenForBets, withoutAnteBets } from '../lib/firebase/bets' import {
Bet,
listenForBets,
listenForRecentBets,
withoutAnteBets,
} from '../lib/firebase/bets'
export const useBets = (contractId: string) => { export const useBets = (contractId: string) => {
const [bets, setBets] = useState<Bet[] | undefined>() const [bets, setBets] = useState<Bet[] | undefined>()
@ -25,3 +30,9 @@ export const useBetsWithoutAntes = (contract: Contract, initialBets: Bet[]) => {
return bets return bets
} }
export const useRecentBets = () => {
const [recentBets, setRecentBets] = useState<Bet[] | undefined>()
useEffect(() => listenForRecentBets(setRecentBets), [])
return recentBets
}

View File

@ -36,6 +36,10 @@ export async function getRecentBets() {
return getValues<Bet>(recentBetsQuery) return getValues<Bet>(recentBetsQuery)
} }
export function listenForRecentBets(setBets: (bets: Bet[]) => void) {
return listenForValues<Bet>(recentBetsQuery, setBets)
}
export async function getRecentContractBets(contractId: string) { export async function getRecentContractBets(contractId: string) {
const q = query( const q = query(
getBetsCollection(contractId), getBetsCollection(contractId),