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

View File

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

View File

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