Store hotContracts as static props
This commit is contained in:
parent
3f8053e70c
commit
8389ebd6d8
|
@ -5,14 +5,14 @@ import Textarea from 'react-expanding-textarea'
|
||||||
import { useState } from 'react'
|
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 } from '../lib/firebase/users'
|
import { firebaseLogin, User } from '../lib/firebase/users'
|
||||||
import { useHotContracts } from '../hooks/use-contracts'
|
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'
|
||||||
|
|
||||||
export function FeedPromo() {
|
export function FeedPromo(props: { hotContracts: Contract[] }) {
|
||||||
// TODO: Encode in static props
|
const contracts = useHotContracts() ?? props.hotContracts
|
||||||
const hotContracts = useHotContracts()
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
@ -42,10 +42,7 @@ export function FeedPromo() {
|
||||||
</div>
|
</div>
|
||||||
<Spacer h={4} />
|
<Spacer h={4} />
|
||||||
|
|
||||||
<ContractsGrid
|
<ContractsGrid contracts={contracts?.slice(0, 2) || []} showHotVolume />
|
||||||
contracts={hotContracts?.slice(0, 2) || []}
|
|
||||||
showHotVolume
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="text-gray-800 text-lg mb-0 mt-6 mx-6">
|
<div className="text-gray-800 text-lg mb-0 mt-6 mx-6">
|
||||||
|
@ -66,15 +63,10 @@ function Hashtag(props: { tag: string }) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function FeedCreate() {
|
export default function FeedCreate(props: { user: User }) {
|
||||||
const user = useUser()
|
const { user } = props
|
||||||
const [question, setQuestion] = useState('')
|
const [question, setQuestion] = useState('')
|
||||||
|
|
||||||
if (!user) {
|
|
||||||
// TODO: Improve logged-out experience
|
|
||||||
return <FeedPromo />
|
|
||||||
}
|
|
||||||
|
|
||||||
const placeholders = [
|
const placeholders = [
|
||||||
'Will I make a new friend this week?',
|
'Will I make a new friend this week?',
|
||||||
'Will we discover that the world is a simulation?',
|
'Will we discover that the world is a simulation?',
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
import { Contract, listAllContracts } from '../lib/firebase/contracts'
|
import {
|
||||||
|
Contract,
|
||||||
|
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 {
|
||||||
|
@ -9,14 +13,16 @@ import {
|
||||||
listAllComments,
|
listAllComments,
|
||||||
} from '../lib/firebase/comments'
|
} from '../lib/firebase/comments'
|
||||||
import { Bet, listAllBets } from '../lib/firebase/bets'
|
import { Bet, listAllBets } from '../lib/firebase/bets'
|
||||||
import FeedCreate from '../components/feed-create'
|
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'
|
||||||
|
|
||||||
export async function getStaticProps() {
|
export async function getStaticProps() {
|
||||||
const [contracts, recentComments] = await Promise.all([
|
const [contracts, recentComments, hotContracts] = await Promise.all([
|
||||||
listAllContracts().catch((_) => []),
|
listAllContracts().catch((_) => []),
|
||||||
getRecentComments().catch(() => []),
|
getRecentComments().catch(() => []),
|
||||||
|
getHotContracts().catch(() => []),
|
||||||
])
|
])
|
||||||
|
|
||||||
const activeContracts = findActiveContracts(contracts, recentComments)
|
const activeContracts = findActiveContracts(contracts, recentComments)
|
||||||
|
@ -32,6 +38,7 @@ export async function getStaticProps() {
|
||||||
activeContracts,
|
activeContracts,
|
||||||
activeContractBets,
|
activeContractBets,
|
||||||
activeContractComments,
|
activeContractComments,
|
||||||
|
hotContracts,
|
||||||
},
|
},
|
||||||
|
|
||||||
revalidate: 60, // regenerate after a minute
|
revalidate: 60, // regenerate after a minute
|
||||||
|
@ -42,15 +49,27 @@ const Home = (props: {
|
||||||
activeContracts: Contract[]
|
activeContracts: Contract[]
|
||||||
activeContractBets: Bet[][]
|
activeContractBets: Bet[][]
|
||||||
activeContractComments: Comment[][]
|
activeContractComments: Comment[][]
|
||||||
|
hotContracts: Contract[]
|
||||||
}) => {
|
}) => {
|
||||||
const { activeContracts, activeContractBets, activeContractComments } = props
|
const {
|
||||||
|
activeContracts,
|
||||||
|
activeContractBets,
|
||||||
|
activeContractComments,
|
||||||
|
hotContracts,
|
||||||
|
} = props
|
||||||
|
|
||||||
|
const user = useUser()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Page>
|
<Page>
|
||||||
<Col className="items-center">
|
<Col className="items-center">
|
||||||
<Col className="max-w-3xl">
|
<Col className="max-w-3xl">
|
||||||
<div className="-mx-2 sm:mx-0">
|
<div className="-mx-2 sm:mx-0">
|
||||||
<FeedCreate />
|
{user ? (
|
||||||
|
<FeedCreate user={user} />
|
||||||
|
) : (
|
||||||
|
<FeedPromo hotContracts={hotContracts} />
|
||||||
|
)}
|
||||||
<Spacer h={4} />
|
<Spacer h={4} />
|
||||||
<ActivityFeed
|
<ActivityFeed
|
||||||
contracts={activeContracts}
|
contracts={activeContracts}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user