From a5e4411075563e897545759b05020d054c2beffc Mon Sep 17 00:00:00 2001 From: jahooma Date: Thu, 30 Dec 2021 13:35:29 -0500 Subject: [PATCH] Load all contracts, and filter to 99 client-side. --- web/components/contracts-list.tsx | 5 +++++ web/lib/firebase/contracts.ts | 4 ++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/web/components/contracts-list.tsx b/web/components/contracts-list.tsx index 74c94ad5..b80ade7c 100644 --- a/web/components/contracts-list.tsx +++ b/web/components/contracts-list.tsx @@ -110,6 +110,8 @@ function ContractsGrid(props: { contracts: Contract[] }) { ) } +const MAX_CONTRACTS_DISPLAYED = 99 + type Sort = 'createdTime' | 'pool' | 'resolved' | 'all' export function SearchableGrid(props: { contracts: Contract[] @@ -143,6 +145,9 @@ export function SearchableGrid(props: { ) } + if (matches.length > MAX_CONTRACTS_DISPLAYED) + matches = _.slice(matches, 0, MAX_CONTRACTS_DISPLAYED) + return (
{/* Show a search input next to a sort dropdown */} diff --git a/web/lib/firebase/contracts.ts b/web/lib/firebase/contracts.ts index f97e111c..b8ea93e3 100644 --- a/web/lib/firebase/contracts.ts +++ b/web/lib/firebase/contracts.ts @@ -107,7 +107,7 @@ export async function listContracts(creatorId: string): Promise { } export async function listAllContracts(): Promise { - const q = query(contractCollection, orderBy('createdTime', 'desc'), limit(99)) + const q = query(contractCollection, orderBy('createdTime', 'desc')) const snapshot = await getDocs(q) return snapshot.docs.map((doc) => doc.data() as Contract) } @@ -115,7 +115,7 @@ export async function listAllContracts(): Promise { export function listenForContracts( setContracts: (contracts: Contract[]) => void ) { - const q = query(contractCollection, orderBy('createdTime', 'desc'), limit(99)) + const q = query(contractCollection, orderBy('createdTime', 'desc')) return onSnapshot(q, (snap) => { setContracts(snap.docs.map((doc) => doc.data() as Contract)) })