Apply tag and creatorId filters to contract firestore search
This commit is contained in:
parent
8ced159d9a
commit
8d7bf6fb64
|
@ -123,7 +123,7 @@ export function ContractSearch(props: {
|
||||||
const indexName = `${indexPrefix}contracts-${sort}`
|
const indexName = `${indexPrefix}contracts-${sort}`
|
||||||
|
|
||||||
if (IS_PRIVATE_MANIFOLD) {
|
if (IS_PRIVATE_MANIFOLD) {
|
||||||
return <ContractSearchFirestore querySortOptions={querySortOptions} />
|
return <ContractSearchFirestore querySortOptions={querySortOptions} additionalFilter={additionalFilter} />
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
|
@ -14,9 +14,13 @@ export default function ContractSearchFirestore(props: {
|
||||||
defaultSort: Sort
|
defaultSort: Sort
|
||||||
shouldLoadFromStorage?: boolean
|
shouldLoadFromStorage?: boolean
|
||||||
}
|
}
|
||||||
|
additionalFilter?: {
|
||||||
|
creatorId?: string
|
||||||
|
tag?: string
|
||||||
|
}
|
||||||
}) {
|
}) {
|
||||||
const contracts = useContracts()
|
const contracts = useContracts()
|
||||||
const { querySortOptions } = props
|
const { querySortOptions, additionalFilter } = props
|
||||||
|
|
||||||
const { initialSort, initialQuery } = useInitialQueryAndSort(querySortOptions)
|
const { initialSort, initialQuery } = useInitialQueryAndSort(querySortOptions)
|
||||||
const [sort, setSort] = useState(initialSort || 'newest')
|
const [sort, setSort] = useState(initialSort || 'newest')
|
||||||
|
@ -62,6 +66,20 @@ export default function ContractSearchFirestore(props: {
|
||||||
matches = sortBy(matches, ({ volume24Hours }) => -1 * volume24Hours)
|
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)
|
const showTime = ['close-date', 'closed'].includes(sort)
|
||||||
? 'close-date'
|
? 'close-date'
|
||||||
: sort === 'resolve-date'
|
: sort === 'resolve-date'
|
||||||
|
|
Loading…
Reference in New Issue
Block a user