From 5bad8b27874860b809297dc6622f942c4eb843a4 Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Tue, 14 Dec 2021 23:44:41 -0800 Subject: [PATCH] Hide resolved markets by default --- web/pages/markets.tsx | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/web/pages/markets.tsx b/web/pages/markets.tsx index 047316f0..2bfd5322 100644 --- a/web/pages/markets.tsx +++ b/web/pages/markets.tsx @@ -1,7 +1,6 @@ import React, { useEffect, useState } from 'react' import { ContractsGrid } from '../components/contracts-list' import { Header } from '../components/header' -import { Title } from '../components/title' import { compute, listAllContracts } from '../lib/firebase/contracts' import { Contract } from '../lib/firebase/contracts' @@ -12,28 +11,35 @@ export default function Markets() { }, []) const [query, setQuery] = useState('') - type Sort = 'createdTime' | 'volume' + type Sort = 'createdTime' | 'volume' | 'resolved' | 'all' const [sort, setSort] = useState('volume') function check(corpus: String) { return corpus.toLowerCase().includes(query.toLowerCase()) } - const matches = contracts.filter( + let matches = contracts.filter( (c) => check(c.question) || check(c.description) || check(c.creatorName) ) - if (sort === 'createdTime') { + if (sort === 'createdTime' || sort === 'resolved' || sort === 'all') { matches.sort((a, b) => b.createdTime - a.createdTime) } else if (sort === 'volume') { matches.sort((a, b) => compute(b).volume - compute(a).volume) } + if (sort !== 'all') { + // Filter for (or filter out) resolved contracts + matches = matches.filter((c) => + sort === 'resolved' ? c.resolution : !c.resolution + ) + } + return (
{/* Show a search input next to a sort dropdown */} -
+
+ +
- - <ContractsGrid contracts={matches.filter((c) => !c.resolution)} /> - - <Title text="Resolved markets" className="mt-16" /> - <ContractsGrid contracts={matches.filter((c) => c.resolution)} /> + <ContractsGrid contracts={matches} /> </div> </div> )