Reorg homepage. No feed when not signed in, add back hot & closing soon for signed

This commit is contained in:
jahooma 2022-01-21 18:28:12 -06:00
parent b29e69a52c
commit d357f51883
4 changed files with 41 additions and 25 deletions

View File

@ -1,4 +1,3 @@
import { useUser } from '../hooks/use-user'
import { AvatarWithIcon } from './contract-feed' import { AvatarWithIcon } from './contract-feed'
import { Title } from './title' import { Title } from './title'
import Textarea from 'react-expanding-textarea' import Textarea from 'react-expanding-textarea'
@ -6,13 +5,12 @@ import { useState } from 'react'
import { Spacer } from './layout/spacer' import { Spacer } from './layout/spacer'
import { NewContract } from '../pages/create' import { NewContract } from '../pages/create'
import { firebaseLogin, User } from '../lib/firebase/users' import { firebaseLogin, User } from '../lib/firebase/users'
import { useHotContracts } from '../hooks/use-contracts'
import { ContractsGrid } from './contracts-list' import { ContractsGrid } from './contracts-list'
import { SiteLink } from './site-link' import { SiteLink } from './site-link'
import { Contract } from '../../common/contract' import { Contract } from '../../common/contract'
export function FeedPromo(props: { hotContracts: Contract[] }) { export function FeedPromo(props: { hotContracts: Contract[] }) {
const contracts = useHotContracts() ?? props.hotContracts const { hotContracts } = props
return ( return (
<> <>
@ -42,11 +40,10 @@ export function FeedPromo(props: { hotContracts: Contract[] }) {
</div> </div>
<Spacer h={4} /> <Spacer h={4} />
<ContractsGrid contracts={contracts?.slice(0, 2) || []} showHotVolume /> <ContractsGrid
</div> contracts={hotContracts?.slice(0, 6) || []}
showHotVolume
<div className="text-gray-800 text-lg mb-0 mt-6 mx-6"> />
Recent community activity
</div> </div>
</> </>
) )

View File

@ -153,7 +153,7 @@ export function listenForHotContracts(
export async function getHotContracts() { export async function getHotContracts() {
const contracts = await getValues<Contract>(hotContractsQuery) const contracts = await getValues<Contract>(hotContractsQuery)
return _.sortBy( return _.sortBy(
chooseRandomSubset(contracts, 4), chooseRandomSubset(contracts, 6),
(contract) => -1 * contract.volume24Hours (contract) => -1 * contract.volume24Hours
) )
} }

View File

@ -2,6 +2,7 @@ import React from 'react'
import _ from 'lodash' import _ from 'lodash'
import { import {
Contract, Contract,
getClosingSoonContracts,
getHotContracts, getHotContracts,
listAllContracts, listAllContracts,
} from '../lib/firebase/contracts' } from '../lib/firebase/contracts'
@ -19,13 +20,16 @@ import FeedCreate, { FeedPromo } 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 { ClosingSoonMarkets, HotMarkets } from './markets'
export async function getStaticProps() { export async function getStaticProps() {
const [contracts, recentComments, hotContracts] = await Promise.all([ const [contracts, recentComments, hotContracts, closingSoonContracts] =
listAllContracts().catch((_) => []), await Promise.all([
getRecentComments().catch(() => []), listAllContracts().catch((_) => []),
getHotContracts().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(
@ -41,6 +45,7 @@ export async function getStaticProps() {
activeContractBets, activeContractBets,
activeContractComments, activeContractComments,
hotContracts, hotContracts,
closingSoonContracts,
}, },
revalidate: 60, // regenerate after a minute revalidate: 60, // regenerate after a minute
@ -52,8 +57,14 @@ const Home = (props: {
activeContractBets: Bet[][] activeContractBets: Bet[][]
activeContractComments: Comment[][] activeContractComments: Comment[][]
hotContracts: Contract[] hotContracts: Contract[]
closingSoonContracts: Contract[]
}) => { }) => {
const { activeContractBets, activeContractComments, hotContracts } = props const {
activeContractBets,
activeContractComments,
hotContracts,
closingSoonContracts,
} = props
const contracts = useContracts() ?? props.activeContracts const contracts = useContracts() ?? props.activeContracts
const recentComments = useRecentComments() const recentComments = useRecentComments()
@ -69,16 +80,24 @@ const Home = (props: {
<Col className="max-w-3xl"> <Col className="max-w-3xl">
<div className="-mx-2 sm:mx-0"> <div className="-mx-2 sm:mx-0">
{user ? ( {user ? (
<FeedCreate user={user} /> <>
<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}
/>
</>
) : ( ) : (
<FeedPromo hotContracts={hotContracts} /> <>
<FeedPromo hotContracts={hotContracts} />
</>
)} )}
<Spacer h={4} />
<ActivityFeed
contracts={activeContracts}
contractBets={activeContractBets}
contractComments={activeContractComments}
/>
</div> </div>
</Col> </Col>
</Col> </Col>

View File

@ -64,7 +64,7 @@ export default function Markets(props: {
) )
} }
const HotMarkets = (props: { contracts: Contract[] }) => { export const HotMarkets = (props: { contracts: Contract[] }) => {
const { contracts } = props const { contracts } = props
if (contracts.length === 0) return <></> if (contracts.length === 0) return <></>
@ -76,7 +76,7 @@ const HotMarkets = (props: { contracts: Contract[] }) => {
) )
} }
const ClosingSoonMarkets = (props: { contracts: Contract[] }) => { export const ClosingSoonMarkets = (props: { contracts: Contract[] }) => {
const { contracts } = props const { contracts } = props
if (contracts.length === 0) return <></> if (contracts.length === 0) return <></>