diff --git a/web/pages/markets.tsx b/web/pages/markets.tsx index cbc6c934..ef9836ad 100644 --- a/web/pages/markets.tsx +++ b/web/pages/markets.tsx @@ -88,15 +88,60 @@ export default function Markets() { listAllContracts().then(setContracts) }, []) + const [query, setQuery] = useState('') + type Sort = 'createdTime' | 'volume' + const [sort, setSort] = useState('createdTime') + + function check(corpus: String) { + return corpus.toLowerCase().includes(query.toLowerCase()) + } + const matches = contracts.filter( + (c) => check(c.question) || check(c.description) || check(c.creatorName) + ) + + function volume(contract: Contract) { + return ( + contract.pot.YES + + contract.pot.NO - + contract.seedAmounts.YES - + contract.seedAmounts.NO + ) + } + + if (sort === 'createdTime') { + matches.sort((a, b) => b.createdTime - a.createdTime) + } else if (sort === 'volume') { + matches.sort((a, b) => volume(b) - volume(a)) + } + return (