manifold/web/pages/index.tsx

45 lines
891 B
TypeScript
Raw Normal View History

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