manifold/web/pages/index.tsx

47 lines
1.0 KiB
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-08 06:23:50 +00:00
const { contracts, hotContractIds } = props
const hotContracts = hotContractIds.map(
(id) => contracts.find((contract) => contract.id === id) as Contract
)
2022-01-05 06:32:52 +00:00
return user ? (
2022-01-08 06:23:50 +00:00
<Markets contracts={contracts} hotContractIds={hotContractIds} />
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