Show hot markets in fold feed

This commit is contained in:
James Grugett 2022-02-02 23:58:27 -06:00
parent 00ac581736
commit fdbaa5270b
2 changed files with 27 additions and 5 deletions

View File

@ -37,6 +37,16 @@ export async function getRecentBets() {
return getValues<Bet>(recentBetsQuery)
}
export async function getRecentContractBets(contractId: string) {
const q = query(
getBetsCollection(contractId),
where('createdTime', '>', Date.now() - DAY_IN_MS),
orderBy('createdTime', 'desc')
)
return getValues<Bet>(q)
}
export function listenForBets(
contractId: string,
setBets: (bets: Bet[]) => void

View File

@ -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(
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(