Load all contracts, and filter to 99 client-side.

This commit is contained in:
jahooma 2021-12-30 13:35:29 -05:00
parent a9e1cbc0be
commit a5e4411075
2 changed files with 7 additions and 2 deletions

View File

@ -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 (
<div>
{/* Show a search input next to a sort dropdown */}

View File

@ -107,7 +107,7 @@ export async function listContracts(creatorId: string): Promise<Contract[]> {
}
export async function listAllContracts(): Promise<Contract[]> {
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<Contract[]> {
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))
})