Collapsable bets, with bet table collapsed by default

This commit is contained in:
jahooma 2021-12-16 15:22:00 -06:00
parent 9289ad1f37
commit 21d0eca49f
2 changed files with 58 additions and 28 deletions

View File

@ -89,17 +89,26 @@ function MyContractBets(props: { contract: Contract; bets: Bet[] }) {
const { bets, contract } = props const { bets, contract } = props
const { resolution } = contract const { resolution } = contract
const [collapsed, setCollapsed] = useState(true)
return ( return (
<div className="p-6 bg-white card card-body shadow-xl"> <div
tabIndex={0}
className={clsx(
'p-6 bg-white card card-body shadow-xl collapse collapse-arrow cursor-pointer',
collapsed ? 'collapse-close' : 'collapse-open'
)}
onClick={() => setCollapsed((collapsed) => !collapsed)}
>
<Row> <Row>
<Col className="w-2/3"> <Col className="flex-[2] gap-1">
<div>
<Link href={path(contract)}> <Link href={path(contract)}>
<a> <a className="font-medium text-indigo-700 hover:underline hover:decoration-indigo-400 hover:decoration-2">
<div className="font-medium text-indigo-700 mb-1 hover:underline hover:decoration-indigo-400 hover:decoration-2">
{contract.question} {contract.question}
</div>
</a> </a>
</Link> </Link>
</div>
<Row className="gap-2 text-gray-500 text-sm"> <Row className="gap-2 text-gray-500 text-sm">
<div> <div>
@ -109,23 +118,32 @@ function MyContractBets(props: { contract: Contract; bets: Bet[] }) {
<> <>
<div></div> <div></div>
<div> <div>
Resolved {resolution === 'YES' && <YesLabel />} Resolved <OutcomeLabel outcome={resolution} />
{resolution === 'NO' && <NoLabel />}
{resolution === 'CANCEL' && <CancelLabel />}
</div> </div>
</> </>
)} )}
</Row> </Row>
</Col> </Col>
{/* Show this at the end of the flex */} <MyBetsSummary
<MyBetsSummary contract={contract} bets={bets} className="ml-auto" /> className="flex-1 justify-end"
contract={contract}
bets={bets}
/>
{/* Show carrot for collapsing. Hack the positioning. */}
<div
className="collapse-title p-0 pr-8 relative w-0 h-0 min-h-0"
style={{ top: -10, right: -20 }}
/>
</Row> </Row>
<div className="collapse-content" style={{ backgroundColor: 'white' }}>
<Spacer h={8} /> <Spacer h={8} />
<ContractBetsTable contract={contract} bets={bets} /> <ContractBetsTable contract={contract} bets={bets} />
</div> </div>
</div>
) )
} }
@ -183,13 +201,17 @@ export function MyBetsSummary(props: {
) )
} }
export function ContractBetsTable(props: { contract: Contract; bets: Bet[] }) { export function ContractBetsTable(props: {
const { contract, bets } = props contract: Contract
bets: Bet[]
className?: string
}) {
const { contract, bets, className } = props
const { isResolved } = contract const { isResolved } = contract
return ( return (
<div className="overflow-x-auto"> <div className={clsx('overflow-x-auto', className)}>
<table className="table table-zebra table-compact text-gray-500 w-full"> <table className="table table-zebra table-compact text-gray-500 w-full">
<thead> <thead>
<tr className="p-2"> <tr className="p-2">
@ -219,7 +241,9 @@ function BetRow(props: { bet: Bet; contract: Contract }) {
return ( return (
<tr> <tr>
<td>{dayjs(createdTime).format('MMM D, H:mma')}</td> <td>{dayjs(createdTime).format('MMM D, H:mma')}</td>
<td>{outcome}</td> <td>
<OutcomeLabel outcome={outcome} />
</td>
<td>{formatMoney(amount)}</td> <td>{formatMoney(amount)}</td>
<td> <td>
{formatPercent(probBefore)} {formatPercent(probAfter)} {formatPercent(probBefore)} {formatPercent(probAfter)}
@ -236,6 +260,14 @@ function BetRow(props: { bet: Bet; contract: Contract }) {
) )
} }
function OutcomeLabel(props: { outcome: 'YES' | 'NO' | 'CANCEL' }) {
const { outcome } = props
if (outcome === 'YES') return <YesLabel />
if (outcome === 'NO') return <NoLabel />
return <CancelLabel />
}
function YesLabel() { function YesLabel() {
return <span className="text-primary">YES</span> return <span className="text-primary">YES</span>
} }

View File

@ -101,17 +101,15 @@ function BetsSection(props: { contract: Contract; user: User | null }) {
const userBets = user && bets.filter((bet) => bet.userId === user.id) const userBets = user && bets.filter((bet) => bet.userId === user.id)
if (!userBets || userBets.length === 0) return <></>
return ( return (
<div className="p-4"> <div className="p-4">
{userBets && userBets.length > 0 && (
<>
<Title text="Your bets" /> <Title text="Your bets" />
<MyBetsSummary contract={contract} bets={userBets} /> <MyBetsSummary contract={contract} bets={userBets} />
<Spacer h={6} /> <Spacer h={6} />
<ContractBetsTable contract={contract} bets={userBets} /> <ContractBetsTable contract={contract} bets={userBets} />
<Spacer h={6} /> <Spacer h={6} />
</>
)}
</div> </div>
) )
} }