import React from 'react'
import _ from 'lodash'
import {
Contract,
getHotContracts,
listAllContracts,
} from '../lib/firebase/contracts'
import { Spacer } from '../components/layout/spacer'
import { Page } from '../components/page'
import { Title } from '../components/title'
import { ActivityFeed, findActiveContracts } from './activity'
import {
getRecentComments,
Comment,
listAllComments,
} from '../lib/firebase/comments'
import { Col } from '../components/layout/col'
import { ContractCard } from '../components/contract-card'
import { Bet, listAllBets } from '../lib/firebase/bets'
export async function getStaticProps() {
const [contracts, hotContracts, recentComments] = await Promise.all([
listAllContracts().catch((_) => []),
getHotContracts().catch(() => []),
getRecentComments().catch(() => []),
])
const activeContracts = findActiveContracts(contracts, recentComments)
const activeContractBets = await Promise.all(
activeContracts.map((contract) => listAllBets(contract.id))
)
const activeContractComments = await Promise.all(
activeContracts.map((contract) => listAllComments(contract.id))
)
return {
props: {
activeContracts,
activeContractBets,
activeContractComments,
hotContracts,
},
revalidate: 60, // regenerate after a minute
}
}
const Home = (props: {
activeContracts: Contract[]
activeContractBets: Bet[][]
activeContractComments: Comment[][]
hotContracts: Contract[]
}) => {
const {
hotContracts,
activeContracts,
activeContractBets,
activeContractComments,
} = props
return (