From f1a96b5320bd5b26efd03fb8c5bca628cab60de6 Mon Sep 17 00:00:00 2001 From: mantikoros Date: Sat, 18 Dec 2021 23:59:34 -0600 Subject: [PATCH] static loading of markets --- web/pages/index.tsx | 19 ++++++++++++++++--- web/pages/markets.tsx | 19 +++++++++++++++++-- 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/web/pages/index.tsx b/web/pages/index.tsx index 76164807..6e4ba609 100644 --- a/web/pages/index.tsx +++ b/web/pages/index.tsx @@ -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 ? : + + return user ? : } export default Home diff --git a/web/pages/markets.tsx b/web/pages/markets.tsx index a04b039d..f70261ed 100644 --- a/web/pages/markets.tsx +++ b/web/pages/markets.tsx @@ -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 (
- +
) }