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'
|
|
|
|
import Markets from './markets'
|
2021-12-18 01:47:39 +00:00
|
|
|
import LandingPage from './landing-page'
|
2022-01-05 06:32:52 +00:00
|
|
|
import {
|
|
|
|
Contract,
|
|
|
|
getHotContracts,
|
|
|
|
listAllContracts,
|
|
|
|
} from '../lib/firebase/contracts'
|
2021-12-01 04:20:13 +00:00
|
|
|
|
2021-12-19 05:59:34 +00:00
|
|
|
export async function getStaticProps() {
|
2022-01-09 20:26:51 +00:00
|
|
|
const [contracts, hotContracts] = await Promise.all([
|
2022-01-05 06:32:52 +00:00
|
|
|
listAllContracts().catch((_) => []),
|
|
|
|
getHotContracts().catch(() => []),
|
|
|
|
])
|
2021-12-19 05:59:34 +00:00
|
|
|
|
|
|
|
return {
|
|
|
|
props: {
|
|
|
|
contracts,
|
2022-01-09 20:26:51 +00:00
|
|
|
hotContracts,
|
2021-12-19 05:59:34 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
revalidate: 60, // regenerate after a minute
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-09 20:26:51 +00:00
|
|
|
const Home = (props: { contracts: Contract[]; hotContracts: Contract[] }) => {
|
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-09 20:26:51 +00:00
|
|
|
const { contracts, hotContracts } = props
|
2022-01-08 06:23:50 +00:00
|
|
|
|
2022-01-05 06:32:52 +00:00
|
|
|
return user ? (
|
2022-01-09 20:26:51 +00:00
|
|
|
<Markets contracts={contracts} hotContracts={hotContracts} />
|
2022-01-05 06:32:52 +00:00
|
|
|
) : (
|
2022-01-08 06:23:50 +00:00
|
|
|
<LandingPage hotContracts={hotContracts} />
|
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
|