2021-12-03 01:18:00 +00:00
|
|
|
import React from 'react'
|
2022-01-09 20:26:51 +00:00
|
|
|
import _ from 'lodash'
|
2021-12-15 07:24:55 +00:00
|
|
|
import { useUser } from '../hooks/use-user'
|
2022-01-05 06:32:52 +00:00
|
|
|
import {
|
|
|
|
Contract,
|
|
|
|
getHotContracts,
|
|
|
|
listAllContracts,
|
|
|
|
} from '../lib/firebase/contracts'
|
2022-01-12 03:56:11 +00:00
|
|
|
import LandingPage from './landing-page'
|
|
|
|
import { ContractsGrid } from '../components/contracts-list'
|
|
|
|
import { Spacer } from '../components/layout/spacer'
|
|
|
|
import { Page } from '../components/page'
|
|
|
|
import { Title } from '../components/title'
|
|
|
|
import { ActivityFeed } from './activity'
|
|
|
|
import { getRecentComments, Comment } from '../lib/firebase/comments'
|
2021-12-01 04:20:13 +00:00
|
|
|
|
2021-12-19 05:59:34 +00:00
|
|
|
export async function getStaticProps() {
|
2022-01-12 03:56:11 +00:00
|
|
|
const [contracts, hotContracts, recentComments] = await Promise.all([
|
2022-01-05 06:32:52 +00:00
|
|
|
listAllContracts().catch((_) => []),
|
|
|
|
getHotContracts().catch(() => []),
|
2022-01-12 03:56:11 +00:00
|
|
|
getRecentComments().catch(() => []),
|
2022-01-05 06:32:52 +00:00
|
|
|
])
|
2021-12-19 05:59:34 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
props: {
|
|
|
|
contracts,
|
2022-01-09 20:26:51 +00:00
|
|
|
hotContracts,
|
2022-01-12 03:56:11 +00:00
|
|
|
recentComments,
|
2021-12-19 05:59:34 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
revalidate: 60, // regenerate after a minute
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-12 03:56:11 +00:00
|
|
|
const Home = (props: {
|
|
|
|
contracts: Contract[]
|
|
|
|
hotContracts: Contract[]
|
|
|
|
recentComments: Comment[]
|
|
|
|
}) => {
|
2021-12-15 07:24:55 +00:00
|
|
|
const user = useUser()
|
2021-12-17 03:37:36 +00:00
|
|
|
|
|
|
|
if (user === undefined) return <></>
|
2021-12-19 05:59:34 +00:00
|
|
|
|
2022-01-12 03:56:11 +00:00
|
|
|
const { contracts, hotContracts, recentComments } = props
|
|
|
|
|
|
|
|
if (user === null) {
|
|
|
|
return <LandingPage hotContracts={hotContracts} />
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Page>
|
|
|
|
<div className="w-full bg-indigo-50 border-2 border-indigo-100 p-6 rounded-lg shadow-md">
|
|
|
|
<Title className="mt-0" text="🔥 Markets" />
|
|
|
|
<ContractsGrid contracts={hotContracts} showHotVolume />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<Spacer h={10} />
|
2022-01-08 06:23:50 +00:00
|
|
|
|
2022-01-12 03:56:11 +00:00
|
|
|
<ActivityFeed contracts={contracts} recentComments={recentComments} />
|
|
|
|
</Page>
|
2022-01-05 06:32:52 +00:00
|
|
|
)
|
2021-12-17 04:44:48 +00:00
|
|
|
}
|
|
|
|
|
2021-12-02 23:49:46 +00:00
|
|
|
export default Home
|