2021-12-03 01:18:00 +00:00
|
|
|
import React from 'react'
|
2022-01-09 20:26:51 +00:00
|
|
|
import _ from 'lodash'
|
2022-01-05 06:32:52 +00:00
|
|
|
import {
|
|
|
|
Contract,
|
|
|
|
getHotContracts,
|
|
|
|
listAllContracts,
|
|
|
|
} from '../lib/firebase/contracts'
|
2022-01-12 03:56:11 +00:00
|
|
|
import { Spacer } from '../components/layout/spacer'
|
|
|
|
import { Page } from '../components/page'
|
|
|
|
import { Title } from '../components/title'
|
2022-01-15 00:16:25 +00:00
|
|
|
import { ActivityFeed, findActiveContracts } from './activity'
|
|
|
|
import {
|
|
|
|
getRecentComments,
|
|
|
|
Comment,
|
|
|
|
listAllComments,
|
|
|
|
} from '../lib/firebase/comments'
|
2022-01-14 06:55:35 +00:00
|
|
|
import { Col } from '../components/layout/col'
|
|
|
|
import { ContractCard } from '../components/contract-card'
|
2022-01-15 00:16:25 +00:00
|
|
|
import { Bet, listAllBets } from '../lib/firebase/bets'
|
2021-12-01 04:20:13 +00:00
|
|
|
|
2021-12-19 05:59:34 +00:00
|
|
|
export async function getStaticProps() {
|
2022-01-12 03:56:11 +00:00
|
|
|
const [contracts, hotContracts, recentComments] = await Promise.all([
|
2022-01-05 06:32:52 +00:00
|
|
|
listAllContracts().catch((_) => []),
|
|
|
|
getHotContracts().catch(() => []),
|
2022-01-12 03:56:11 +00:00
|
|
|
getRecentComments().catch(() => []),
|
2022-01-05 06:32:52 +00:00
|
|
|
])
|
2021-12-19 05:59:34 +00:00
|
|
|
|
2022-01-15 00:16:25 +00:00
|
|
|
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))
|
|
|
|
)
|
|
|
|
|
2021-12-19 05:59:34 +00:00
|
|
|
return {
|
|
|
|
props: {
|
2022-01-15 00:16:25 +00:00
|
|
|
activeContracts,
|
|
|
|
activeContractBets,
|
|
|
|
activeContractComments,
|
2022-01-09 20:26:51 +00:00
|
|
|
hotContracts,
|
2021-12-19 05:59:34 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
revalidate: 60, // regenerate after a minute
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-12 03:56:11 +00:00
|
|
|
const Home = (props: {
|
2022-01-15 00:16:25 +00:00
|
|
|
activeContracts: Contract[]
|
|
|
|
activeContractBets: Bet[][]
|
|
|
|
activeContractComments: Comment[][]
|
2022-01-12 03:56:11 +00:00
|
|
|
hotContracts: Contract[]
|
|
|
|
}) => {
|
2022-01-15 18:43:39 +00:00
|
|
|
const {
|
|
|
|
activeContracts,
|
|
|
|
activeContractBets,
|
|
|
|
activeContractComments,
|
|
|
|
hotContracts,
|
|
|
|
} = props
|
2022-01-12 03:56:11 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Page>
|
2022-01-14 06:55:35 +00:00
|
|
|
<HotMarkets hotContracts={hotContracts} />
|
2022-01-12 03:56:11 +00:00
|
|
|
<Spacer h={10} />
|
2022-01-15 00:16:25 +00:00
|
|
|
<ActivityFeed
|
|
|
|
contracts={activeContracts}
|
|
|
|
contractBets={activeContractBets}
|
|
|
|
contractComments={activeContractComments}
|
|
|
|
/>
|
2022-01-12 03:56:11 +00:00
|
|
|
</Page>
|
2022-01-05 06:32:52 +00:00
|
|
|
)
|
2021-12-17 04:44:48 +00:00
|
|
|
}
|
|
|
|
|
2022-01-14 06:55:35 +00:00
|
|
|
const HotMarkets = (props: { hotContracts: Contract[] }) => {
|
|
|
|
const { hotContracts } = props
|
2022-01-15 06:43:15 +00:00
|
|
|
if (hotContracts.length < 4) return <></>
|
|
|
|
|
2022-01-14 06:55:35 +00:00
|
|
|
const [c1, c2, c3, c4] = hotContracts
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="w-full bg-indigo-50 border-2 border-indigo-100 p-6 rounded-lg shadow-md">
|
|
|
|
<Title className="mt-0" text="🔥 Markets" />
|
|
|
|
<Col className="gap-6">
|
2022-01-14 18:28:45 +00:00
|
|
|
<Col className="md:flex-row items-start gap-6">
|
2022-01-14 06:55:35 +00:00
|
|
|
<ContractCard className="flex-1" contract={c1} showHotVolume />
|
|
|
|
<ContractCard className="flex-1" contract={c2} showHotVolume />
|
|
|
|
</Col>
|
2022-01-14 18:28:45 +00:00
|
|
|
<Col className="md:flex-row items-start gap-6">
|
2022-01-14 06:55:35 +00:00
|
|
|
<ContractCard className="flex-1" contract={c3} showHotVolume />
|
|
|
|
<ContractCard className="flex-1" contract={c4} showHotVolume />
|
|
|
|
</Col>
|
|
|
|
</Col>
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-12-02 23:49:46 +00:00
|
|
|
export default Home
|