2022-01-23 00:16:23 +00:00
|
|
|
import React from 'react'
|
|
|
|
import Router from 'next/router'
|
|
|
|
|
|
|
|
import {
|
|
|
|
Contract,
|
|
|
|
getClosingSoonContracts,
|
|
|
|
getHotContracts,
|
|
|
|
listAllContracts,
|
|
|
|
} from '../lib/firebase/contracts'
|
|
|
|
import { Page } from '../components/page'
|
|
|
|
import { ActivityFeed, findActiveContracts } from './activity'
|
|
|
|
import {
|
|
|
|
getRecentComments,
|
|
|
|
Comment,
|
|
|
|
listAllComments,
|
|
|
|
} from '../lib/firebase/comments'
|
|
|
|
import { Bet, listAllBets } from '../lib/firebase/bets'
|
|
|
|
import FeedCreate from '../components/feed-create'
|
|
|
|
import { Spacer } from '../components/layout/spacer'
|
|
|
|
import { Col } from '../components/layout/col'
|
|
|
|
import { useUser } from '../hooks/use-user'
|
|
|
|
|
|
|
|
export async function getStaticProps() {
|
|
|
|
const [contracts, recentComments, hotContracts, closingSoonContracts] =
|
|
|
|
await Promise.all([
|
|
|
|
listAllContracts().catch((_) => []),
|
|
|
|
getRecentComments().catch(() => []),
|
|
|
|
getHotContracts().catch(() => []),
|
|
|
|
getClosingSoonContracts().catch(() => []),
|
|
|
|
])
|
|
|
|
|
|
|
|
const activeContracts = findActiveContracts(contracts, recentComments)
|
|
|
|
const activeContractBets = await Promise.all(
|
|
|
|
activeContracts.map((contract) => listAllBets(contract.id).catch((_) => []))
|
|
|
|
)
|
|
|
|
const activeContractComments = await Promise.all(
|
|
|
|
activeContracts.map((contract) =>
|
|
|
|
listAllComments(contract.id).catch((_) => [])
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
return {
|
|
|
|
props: {
|
|
|
|
activeContracts,
|
|
|
|
activeContractBets,
|
|
|
|
activeContractComments,
|
|
|
|
hotContracts,
|
|
|
|
closingSoonContracts,
|
|
|
|
},
|
|
|
|
|
|
|
|
revalidate: 60, // regenerate after a minute
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const Home = (props: {
|
|
|
|
activeContracts: Contract[]
|
|
|
|
activeContractBets: Bet[][]
|
|
|
|
activeContractComments: Comment[][]
|
|
|
|
hotContracts: Contract[]
|
|
|
|
closingSoonContracts: Contract[]
|
|
|
|
}) => {
|
|
|
|
const {
|
2022-01-23 00:36:35 +00:00
|
|
|
activeContracts,
|
2022-01-23 00:16:23 +00:00
|
|
|
activeContractBets,
|
|
|
|
activeContractComments,
|
2022-01-27 20:23:55 +00:00
|
|
|
// hotContracts,
|
|
|
|
// closingSoonContracts,
|
2022-01-23 00:16:23 +00:00
|
|
|
} = props
|
|
|
|
|
|
|
|
const user = useUser()
|
|
|
|
|
2022-01-23 00:36:35 +00:00
|
|
|
// const initialActiveContracts = props.activeContracts ?? []
|
|
|
|
// const contracts = useContracts()
|
|
|
|
// const recentComments = useRecentComments()
|
|
|
|
// const activeContracts =
|
|
|
|
// recentComments && contracts
|
|
|
|
// ? findActiveContracts(contracts, recentComments)
|
|
|
|
// : initialActiveContracts
|
|
|
|
// TODO: get activeContractBets, activeContractComments associated with activeContracts
|
2022-01-23 00:26:56 +00:00
|
|
|
|
2022-01-23 00:16:23 +00:00
|
|
|
if (user === null) {
|
|
|
|
Router.replace('/')
|
|
|
|
return <></>
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Page>
|
|
|
|
<Col className="items-center">
|
|
|
|
<Col className="max-w-3xl">
|
|
|
|
<div className="-mx-2 sm:mx-0">
|
|
|
|
<FeedCreate user={user ?? undefined} />
|
|
|
|
<Spacer h={4} />
|
|
|
|
|
2022-01-27 20:23:55 +00:00
|
|
|
{/* <HotMarkets contracts={hotContracts?.slice(0, 4) ?? []} />
|
2022-01-23 00:16:23 +00:00
|
|
|
<Spacer h={4} />
|
|
|
|
|
|
|
|
<ClosingSoonMarkets contracts={closingSoonContracts ?? []} />
|
2022-01-27 20:23:55 +00:00
|
|
|
<Spacer h={10} /> */}
|
2022-01-23 00:16:23 +00:00
|
|
|
|
|
|
|
<ActivityFeed
|
|
|
|
contracts={activeContracts ?? []}
|
|
|
|
contractBets={activeContractBets ?? []}
|
|
|
|
contractComments={activeContractComments ?? []}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</Col>
|
|
|
|
</Col>
|
|
|
|
</Page>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Home
|