Add "closed" sort option

This commit is contained in:
Austin Chen 2022-03-01 18:00:14 -08:00
parent 5944cada77
commit 6243f132aa
3 changed files with 11 additions and 6 deletions

View File

@ -150,7 +150,8 @@ function AbbrContractDetails(props: {
) : showCloseTime ? ( ) : showCloseTime ? (
<Row className="gap-1"> <Row className="gap-1">
<ClockIcon className="h-5 w-5" /> <ClockIcon className="h-5 w-5" />
Closes {fromNow(closeTime || 0)} {(closeTime || 0) < Date.now() ? 'Closed' : 'Closes'}{' '}
{fromNow(closeTime || 0)}
</Row> </Row>
) : ( ) : (
<Row className="gap-1"> <Row className="gap-1">
@ -312,7 +313,7 @@ function EditableCloseDate(props: {
className="btn btn-xs btn-ghost" className="btn btn-xs btn-ghost"
onClick={() => setIsEditingCloseTime(true)} onClick={() => setIsEditingCloseTime(true)}
> >
<PencilIcon className="inline h-4 w-4 mr-2" /> Edit <PencilIcon className="mr-2 inline h-4 w-4" /> Edit
</button> </button>
))} ))}
</> </>

View File

@ -229,11 +229,13 @@ export function SearchableGrid(props: {
) )
} else if (sort === 'oldest') { } else if (sort === 'oldest') {
matches.sort((a, b) => a.createdTime - b.createdTime) matches.sort((a, b) => a.createdTime - b.createdTime)
} else if (sort === 'close-date') { } else if (sort === 'close-date' || sort === 'closed') {
matches = _.sortBy(matches, ({ volume24Hours }) => -1 * volume24Hours) matches = _.sortBy(matches, ({ volume24Hours }) => -1 * volume24Hours)
matches = _.sortBy(matches, (contract) => contract.closeTime) matches = _.sortBy(matches, (contract) => contract.closeTime)
// Hide contracts that have already closed const hideClosed = sort === 'closed'
matches = matches.filter(({ closeTime }) => (closeTime || 0) > Date.now()) matches = matches.filter(
({ closeTime }) => closeTime && closeTime > Date.now() !== hideClosed
)
} else if (sort === 'most-traded') { } else if (sort === 'most-traded') {
matches.sort( matches.sort(
(a, b) => contractMetrics(b).truePool - contractMetrics(a).truePool (a, b) => contractMetrics(b).truePool - contractMetrics(a).truePool
@ -272,6 +274,7 @@ export function SearchableGrid(props: {
<option value="most-traded">Most traded</option> <option value="most-traded">Most traded</option>
<option value="24-hour-vol">24h volume</option> <option value="24-hour-vol">24h volume</option>
<option value="close-date">Closing soon</option> <option value="close-date">Closing soon</option>
<option value="closed">Closed</option>
<option value="newest">Newest</option> <option value="newest">Newest</option>
<option value="oldest">Oldest</option> <option value="oldest">Oldest</option>
@ -289,7 +292,7 @@ export function SearchableGrid(props: {
) : ( ) : (
<ContractsGrid <ContractsGrid
contracts={matches} contracts={matches}
showCloseTime={sort == 'close-date'} showCloseTime={['close-date', 'closed'].includes(sort)}
/> />
)} )}
</div> </div>

View File

@ -10,6 +10,7 @@ export type Sort =
| 'most-traded' | 'most-traded'
| '24-hour-vol' | '24-hour-vol'
| 'close-date' | 'close-date'
| 'closed'
| 'resolved' | 'resolved'
| 'all' | 'all'