manifold/web/pages/index.tsx

43 lines
927 B
TypeScript
Raw Normal View History

2021-12-03 01:18:00 +00:00
import React from 'react'
import _ from 'lodash'
import { useUser } from '../hooks/use-user'
import Markets from './markets'
import LandingPage from './landing-page'
2022-01-05 06:32:52 +00:00
import {
Contract,
getHotContracts,
listAllContracts,
} from '../lib/firebase/contracts'
2021-12-19 05:59:34 +00:00
export async function getStaticProps() {
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,
hotContracts,
2021-12-19 05:59:34 +00:00
},
revalidate: 60, // regenerate after a minute
}
}
const Home = (props: { contracts: Contract[]; hotContracts: Contract[] }) => {
const user = useUser()
if (user === undefined) return <></>
2021-12-19 05:59:34 +00:00
const { contracts, hotContracts } = props
2022-01-08 06:23:50 +00:00
2022-01-05 06:32:52 +00:00
return user ? (
<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
)
}
export default Home