From 8d7bf6fb64dccbc15aa18d0c998fb55550ab3cf8 Mon Sep 17 00:00:00 2001 From: James Grugett Date: Fri, 24 Jun 2022 12:08:06 -0500 Subject: [PATCH] Apply tag and creatorId filters to contract firestore search --- web/components/contract-search.tsx | 2 +- web/pages/contract-search-firestore.tsx | 20 +++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/web/components/contract-search.tsx b/web/components/contract-search.tsx index e75aefb8..25688d4a 100644 --- a/web/components/contract-search.tsx +++ b/web/components/contract-search.tsx @@ -123,7 +123,7 @@ export function ContractSearch(props: { const indexName = `${indexPrefix}contracts-${sort}` if (IS_PRIVATE_MANIFOLD) { - return + return } return ( diff --git a/web/pages/contract-search-firestore.tsx b/web/pages/contract-search-firestore.tsx index 00d8fe49..c9a7a666 100644 --- a/web/pages/contract-search-firestore.tsx +++ b/web/pages/contract-search-firestore.tsx @@ -14,9 +14,13 @@ export default function ContractSearchFirestore(props: { defaultSort: Sort shouldLoadFromStorage?: boolean } + additionalFilter?: { + creatorId?: string + tag?: string + } }) { const contracts = useContracts() - const { querySortOptions } = props + const { querySortOptions, additionalFilter } = props const { initialSort, initialQuery } = useInitialQueryAndSort(querySortOptions) const [sort, setSort] = useState(initialSort || 'newest') @@ -62,6 +66,20 @@ export default function ContractSearchFirestore(props: { matches = sortBy(matches, ({ volume24Hours }) => -1 * volume24Hours) } + if (additionalFilter) { + const { creatorId, tag } = additionalFilter + + if (creatorId) { + matches = matches.filter((c) => c.creatorId === creatorId) + } + + if (tag) { + matches = matches.filter((c) => + c.lowercaseTags.includes(tag.toLowerCase()) + ) + } + } + const showTime = ['close-date', 'closed'].includes(sort) ? 'close-date' : sort === 'resolve-date'