static loading of markets

This commit is contained in:
mantikoros 2021-12-18 23:59:34 -06:00
parent ab2011609f
commit f1a96b5320
2 changed files with 33 additions and 5 deletions

View File

@ -1,15 +1,28 @@
import React from 'react'
import type { NextPage } from 'next'
import { useUser } from '../hooks/use-user'
import Markets from './markets'
import LandingPage from './landing-page'
import { Contract, listAllContracts } from '../lib/firebase/contracts'
const Home: NextPage = () => {
export async function getStaticProps() {
const contracts = await listAllContracts().catch((_) => [])
return {
props: {
contracts,
},
revalidate: 60, // regenerate after a minute
}
}
const Home = (props: { contracts: Contract[] }) => {
const user = useUser()
if (user === undefined) return <></>
return user ? <Markets /> : <LandingPage />
return user ? <Markets contracts={props.contracts} /> : <LandingPage />
}
export default Home

View File

@ -1,14 +1,29 @@
import { SearchableGrid } from '../components/contracts-list'
import { Header } from '../components/header'
import { useContracts } from '../hooks/use-contracts'
import { Contract, listAllContracts } from '../lib/firebase/contracts'
export default function Markets() {
export async function getStaticProps() {
const contracts = await listAllContracts().catch((_) => [])
return {
props: {
contracts,
},
revalidate: 60, // regenerate after a minute
}
}
export default function Markets(props: { contracts: Contract[] }) {
const contracts = useContracts()
return (
<div className="max-w-4xl px-4 pb-8 mx-auto">
<Header />
<SearchableGrid contracts={contracts === 'loading' ? [] : contracts} />
<SearchableGrid
contracts={contracts === 'loading' ? props.contracts || [] : contracts}
/>
</div>
)
}