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,
|
2022-01-22 00:28:12 +00:00
|
|
|
getClosingSoonContracts,
|
2022-01-05 06:32:52 +00:00
|
|
|
getHotContracts,
|
|
|
|
listAllContracts,
|
|
|
|
} from '../lib/firebase/contracts'
|
2022-01-12 03:56:11 +00:00
|
|
|
import { Page } from '../components/page'
|
2022-01-15 00:16:25 +00:00
|
|
|
import { ActivityFeed, findActiveContracts } from './activity'
|
|
|
|
import {
|
|
|
|
getRecentComments,
|
|
|
|
Comment,
|
|
|
|
listAllComments,
|
|
|
|
} from '../lib/firebase/comments'
|
|
|
|
import { Bet, listAllBets } from '../lib/firebase/bets'
|
2022-01-21 23:21:46 +00:00
|
|
|
import { useContracts } from '../hooks/use-contracts'
|
|
|
|
import { useRecentComments } from '../hooks/use-comments'
|
2022-01-21 18:33:58 +00:00
|
|
|
import FeedCreate, { FeedPromo } from '../components/feed-create'
|
|
|
|
import { Spacer } from '../components/layout/spacer'
|
|
|
|
import { Col } from '../components/layout/col'
|
|
|
|
import { useUser } from '../hooks/use-user'
|
2022-01-22 00:28:12 +00:00
|
|
|
import { ClosingSoonMarkets, HotMarkets } from './markets'
|
2021-12-01 04:20:13 +00:00
|
|
|
|
2021-12-19 05:59:34 +00:00
|
|
|
export async function getStaticProps() {
|
2022-01-22 00:28:12 +00:00
|
|
|
const [contracts, recentComments, hotContracts, closingSoonContracts] =
|
|
|
|
await Promise.all([
|
|
|
|
listAllContracts().catch((_) => []),
|
|
|
|
getRecentComments().catch(() => []),
|
|
|
|
getHotContracts().catch(() => []),
|
|
|
|
getClosingSoonContracts().catch(() => []),
|
|
|
|
])
|
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,
|
2022-01-22 00:28:12 +00:00
|
|
|
closingSoonContracts,
|
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-22 00:28:12 +00:00
|
|
|
closingSoonContracts: Contract[]
|
2022-01-12 03:56:11 +00:00
|
|
|
}) => {
|
2022-01-22 00:28:12 +00:00
|
|
|
const {
|
|
|
|
activeContractBets,
|
|
|
|
activeContractComments,
|
|
|
|
hotContracts,
|
|
|
|
closingSoonContracts,
|
|
|
|
} = props
|
2022-01-21 23:21:46 +00:00
|
|
|
|
|
|
|
const contracts = useContracts() ?? props.activeContracts
|
|
|
|
const recentComments = useRecentComments()
|
|
|
|
const activeContracts = recentComments
|
|
|
|
? findActiveContracts(contracts, recentComments)
|
|
|
|
: props.activeContracts
|
2022-01-12 03:56:11 +00:00
|
|
|
|
2022-01-21 18:33:58 +00:00
|
|
|
const user = useUser()
|
|
|
|
|
2022-01-12 03:56:11 +00:00
|
|
|
return (
|
|
|
|
<Page>
|
2022-01-21 18:33:58 +00:00
|
|
|
<Col className="items-center">
|
|
|
|
<Col className="max-w-3xl">
|
|
|
|
<div className="-mx-2 sm:mx-0">
|
|
|
|
{user ? (
|
2022-01-22 00:28:12 +00:00
|
|
|
<>
|
|
|
|
<FeedCreate user={user} />
|
|
|
|
<Spacer h={4} />
|
|
|
|
<HotMarkets contracts={hotContracts.slice(0, 4)} />
|
|
|
|
<Spacer h={4} />
|
|
|
|
<ClosingSoonMarkets contracts={closingSoonContracts} />
|
|
|
|
<Spacer h={10} />
|
|
|
|
<ActivityFeed
|
|
|
|
contracts={activeContracts}
|
|
|
|
contractBets={activeContractBets}
|
|
|
|
contractComments={activeContractComments}
|
|
|
|
/>
|
|
|
|
</>
|
2022-01-21 18:33:58 +00:00
|
|
|
) : (
|
2022-01-22 00:28:12 +00:00
|
|
|
<>
|
|
|
|
<FeedPromo hotContracts={hotContracts} />
|
|
|
|
</>
|
2022-01-21 18:33:58 +00:00
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</Col>
|
|
|
|
</Col>
|
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
|
|
|
}
|
|
|
|
|
2021-12-02 23:49:46 +00:00
|
|
|
export default Home
|