Listen for updates of contracts on home

This commit is contained in:
James Grugett 2022-01-30 22:03:20 -06:00
parent 6427e1bd06
commit 9d2b99f237

View File

@ -1,12 +1,8 @@
import React from 'react' import React from 'react'
import Router from 'next/router' import Router from 'next/router'
import _ from 'lodash'
import { import { Contract, listAllContracts } from '../lib/firebase/contracts'
Contract,
getClosingSoonContracts,
getHotContracts,
listAllContracts,
} from '../lib/firebase/contracts'
import { Page } from '../components/page' import { Page } from '../components/page'
import { ActivityFeed, findActiveContracts } from './activity' import { ActivityFeed, findActiveContracts } from './activity'
import { import {
@ -19,15 +15,13 @@ import FeedCreate from '../components/feed-create'
import { Spacer } from '../components/layout/spacer' import { Spacer } from '../components/layout/spacer'
import { Col } from '../components/layout/col' import { Col } from '../components/layout/col'
import { useUser } from '../hooks/use-user' import { useUser } from '../hooks/use-user'
import { useContracts } from '../hooks/use-contracts'
export async function getStaticProps() { export async function getStaticProps() {
const [contracts, recentComments, hotContracts, closingSoonContracts] = const [contracts, recentComments] = await Promise.all([
await Promise.all([ listAllContracts().catch((_) => []),
listAllContracts().catch((_) => []), getRecentComments().catch(() => []),
getRecentComments().catch(() => []), ])
getHotContracts().catch(() => []),
getClosingSoonContracts().catch(() => []),
])
const activeContracts = findActiveContracts(contracts, recentComments) const activeContracts = findActiveContracts(contracts, recentComments)
const activeContractBets = await Promise.all( const activeContractBets = await Promise.all(
@ -44,8 +38,6 @@ export async function getStaticProps() {
activeContracts, activeContracts,
activeContractBets, activeContractBets,
activeContractComments, activeContractComments,
hotContracts,
closingSoonContracts,
}, },
revalidate: 60, // regenerate after a minute revalidate: 60, // regenerate after a minute
@ -56,27 +48,18 @@ const Home = (props: {
activeContracts: Contract[] activeContracts: Contract[]
activeContractBets: Bet[][] activeContractBets: Bet[][]
activeContractComments: Comment[][] activeContractComments: Comment[][]
hotContracts: Contract[]
closingSoonContracts: Contract[]
}) => { }) => {
const { const { activeContracts, activeContractBets, activeContractComments } = props
activeContracts,
activeContractBets,
activeContractComments,
// hotContracts,
// closingSoonContracts,
} = props
const user = useUser() const user = useUser()
// const initialActiveContracts = props.activeContracts ?? [] const contracts = useContracts() ?? activeContracts
// const contracts = useContracts() const contractsMap = _.fromPairs(
// const recentComments = useRecentComments() contracts.map((contract) => [contract.id, contract])
// const activeContracts = )
// recentComments && contracts const updatedContracts = activeContracts.map(
// ? findActiveContracts(contracts, recentComments) (contract) => contractsMap[contract.id]
// : initialActiveContracts )
// TODO: get activeContractBets, activeContractComments associated with activeContracts
if (user === null) { if (user === null) {
Router.replace('/') Router.replace('/')
@ -89,17 +72,10 @@ const Home = (props: {
<Col className="max-w-3xl"> <Col className="max-w-3xl">
<FeedCreate user={user ?? undefined} /> <FeedCreate user={user ?? undefined} />
<Spacer h={4} /> <Spacer h={4} />
{/* <HotMarkets contracts={hotContracts?.slice(0, 4) ?? []} />
<Spacer h={4} />
<ClosingSoonMarkets contracts={closingSoonContracts ?? []} />
<Spacer h={10} /> */}
<ActivityFeed <ActivityFeed
contracts={activeContracts ?? []} contracts={updatedContracts}
contractBets={activeContractBets ?? []} contractBets={activeContractBets}
contractComments={activeContractComments ?? []} contractComments={activeContractComments}
/> />
</Col> </Col>
</Col> </Col>