diff --git a/web/pages/home.tsx b/web/pages/home.tsx index 2ebba4a1..54c2af24 100644 --- a/web/pages/home.tsx +++ b/web/pages/home.tsx @@ -1,12 +1,8 @@ import React from 'react' import Router from 'next/router' +import _ from 'lodash' -import { - Contract, - getClosingSoonContracts, - getHotContracts, - listAllContracts, -} from '../lib/firebase/contracts' +import { Contract, listAllContracts } from '../lib/firebase/contracts' import { Page } from '../components/page' import { ActivityFeed, findActiveContracts } from './activity' import { @@ -19,15 +15,13 @@ import FeedCreate from '../components/feed-create' import { Spacer } from '../components/layout/spacer' import { Col } from '../components/layout/col' import { useUser } from '../hooks/use-user' +import { useContracts } from '../hooks/use-contracts' export async function getStaticProps() { - const [contracts, recentComments, hotContracts, closingSoonContracts] = - await Promise.all([ - listAllContracts().catch((_) => []), - getRecentComments().catch(() => []), - getHotContracts().catch(() => []), - getClosingSoonContracts().catch(() => []), - ]) + const [contracts, recentComments] = await Promise.all([ + listAllContracts().catch((_) => []), + getRecentComments().catch(() => []), + ]) const activeContracts = findActiveContracts(contracts, recentComments) const activeContractBets = await Promise.all( @@ -44,8 +38,6 @@ export async function getStaticProps() { activeContracts, activeContractBets, activeContractComments, - hotContracts, - closingSoonContracts, }, revalidate: 60, // regenerate after a minute @@ -56,27 +48,18 @@ const Home = (props: { activeContracts: Contract[] activeContractBets: Bet[][] activeContractComments: Comment[][] - hotContracts: Contract[] - closingSoonContracts: Contract[] }) => { - const { - activeContracts, - activeContractBets, - activeContractComments, - // hotContracts, - // closingSoonContracts, - } = props + const { activeContracts, activeContractBets, activeContractComments } = props const user = useUser() - // 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 + const contracts = useContracts() ?? activeContracts + const contractsMap = _.fromPairs( + contracts.map((contract) => [contract.id, contract]) + ) + const updatedContracts = activeContracts.map( + (contract) => contractsMap[contract.id] + ) if (user === null) { Router.replace('/') @@ -89,17 +72,10 @@ const Home = (props: {