diff --git a/web/lib/firebase/bets.ts b/web/lib/firebase/bets.ts index 717551b4..5397e8fe 100644 --- a/web/lib/firebase/bets.ts +++ b/web/lib/firebase/bets.ts @@ -37,6 +37,16 @@ export async function getRecentBets() { return getValues(recentBetsQuery) } +export async function getRecentContractBets(contractId: string) { + const q = query( + getBetsCollection(contractId), + where('createdTime', '>', Date.now() - DAY_IN_MS), + orderBy('createdTime', 'desc') + ) + + return getValues(q) +} + export function listenForBets( contractId: string, setBets: (bets: Bet[]) => void diff --git a/web/pages/fold/[...slugs]/index.tsx b/web/pages/fold/[...slugs]/index.tsx index 9fde1c18..6841cf27 100644 --- a/web/pages/fold/[...slugs]/index.tsx +++ b/web/pages/fold/[...slugs]/index.tsx @@ -5,7 +5,11 @@ import { Fold } from '../../../../common/fold' import { Comment } from '../../../../common/comment' import { Page } from '../../../components/page' import { Title } from '../../../components/title' -import { Bet, listAllBets } from '../../../lib/firebase/bets' +import { + Bet, + getRecentContractBets, + listAllBets, +} from '../../../lib/firebase/bets' import { listAllComments } from '../../../lib/firebase/comments' import { Contract } from '../../../lib/firebase/contracts' import { @@ -43,14 +47,22 @@ export async function getStaticProps(props: { params: { slugs: string[] } }) { const curatorPromise = fold ? getUser(fold.curatorId) : null const contracts = fold ? await getFoldContracts(fold).catch((_) => []) : [] - const contractComments = await Promise.all( - contracts.map((contract) => listAllComments(contract.id).catch((_) => [])) - ) + + const [contractComments, contractRecentBets] = await Promise.all([ + Promise.all( + contracts.map((contract) => listAllComments(contract.id).catch((_) => [])) + ), + Promise.all( + contracts.map((contract) => + getRecentContractBets(contract.id).catch((_) => []) + ) + ), + ]) let activeContracts = findActiveContracts( contracts, _.flatten(contractComments), - [], + _.flatten(contractRecentBets), 365 ) const [resolved, unresolved] = _.partition(