Reuse ResolutionOrChance component. Make smaller for card, larger for contract page.
This commit is contained in:
parent
657b6b2763
commit
b375256e96
|
@ -5,27 +5,13 @@ import { formatMoney } from '../lib/util/format'
|
||||||
import { UserLink } from './user-page'
|
import { UserLink } from './user-page'
|
||||||
import { Linkify } from './linkify'
|
import { Linkify } from './linkify'
|
||||||
import { Contract, compute, path } from '../lib/firebase/contracts'
|
import { Contract, compute, path } from '../lib/firebase/contracts'
|
||||||
|
import { Col } from './layout/col'
|
||||||
|
|
||||||
export function ContractCard(props: { contract: Contract }) {
|
export function ContractCard(props: { contract: Contract }) {
|
||||||
const { contract } = props
|
const { contract } = props
|
||||||
|
const { resolution } = contract
|
||||||
const { probPercent } = compute(contract)
|
const { probPercent } = compute(contract)
|
||||||
|
|
||||||
const resolutionColor = {
|
|
||||||
YES: 'text-primary',
|
|
||||||
NO: 'text-red-400',
|
|
||||||
MKT: 'text-blue-400',
|
|
||||||
CANCEL: 'text-yellow-400',
|
|
||||||
'': '', // Empty if unresolved
|
|
||||||
}[contract.resolution || '']
|
|
||||||
|
|
||||||
const resolutionText = {
|
|
||||||
YES: 'YES',
|
|
||||||
NO: 'NO',
|
|
||||||
MKT: 'MKT',
|
|
||||||
CANCEL: 'N/A',
|
|
||||||
'': '',
|
|
||||||
}[contract.resolution || '']
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Link href={path(contract)}>
|
<Link href={path(contract)}>
|
||||||
<a>
|
<a>
|
||||||
|
@ -36,14 +22,11 @@ export function ContractCard(props: { contract: Contract }) {
|
||||||
<p className="font-medium text-indigo-700">
|
<p className="font-medium text-indigo-700">
|
||||||
<Linkify text={contract.question} />
|
<Linkify text={contract.question} />
|
||||||
</p>
|
</p>
|
||||||
<div className={clsx('text-4xl', resolutionColor)}>
|
<ResolutionOrChance
|
||||||
{resolutionText || (
|
className="items-center"
|
||||||
<div className="text-primary">
|
resolution={resolution}
|
||||||
{probPercent}
|
probPercent={probPercent}
|
||||||
<div className="text-lg">chance</div>
|
/>
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
</Row>
|
</Row>
|
||||||
<ContractDetails contract={contract} />
|
<ContractDetails contract={contract} />
|
||||||
</div>
|
</div>
|
||||||
|
@ -54,6 +37,55 @@ export function ContractCard(props: { contract: Contract }) {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function ResolutionOrChance(props: {
|
||||||
|
resolution?: 'YES' | 'NO' | 'MKT' | 'CANCEL'
|
||||||
|
probPercent: string
|
||||||
|
large?: boolean
|
||||||
|
className?: string
|
||||||
|
}) {
|
||||||
|
const { resolution, probPercent, large, className } = props
|
||||||
|
|
||||||
|
const resolutionColor = {
|
||||||
|
YES: 'text-primary',
|
||||||
|
NO: 'text-red-400',
|
||||||
|
MKT: 'text-blue-400',
|
||||||
|
CANCEL: 'text-yellow-400',
|
||||||
|
'': '', // Empty if unresolved
|
||||||
|
}[resolution || '']
|
||||||
|
|
||||||
|
const resolutionText = {
|
||||||
|
YES: 'YES',
|
||||||
|
NO: 'NO',
|
||||||
|
MKT: 'MKT',
|
||||||
|
CANCEL: 'N/A',
|
||||||
|
'': '',
|
||||||
|
}[resolution || '']
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Col className={clsx(large ? 'text-4xl' : 'text-3xl', className)}>
|
||||||
|
{resolution ? (
|
||||||
|
<>
|
||||||
|
<div
|
||||||
|
className={clsx('text-gray-500', large ? 'text-xl' : 'text-base')}
|
||||||
|
>
|
||||||
|
Resolved
|
||||||
|
</div>
|
||||||
|
<div className={resolutionColor}>{resolutionText}</div>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<div className="text-primary">{probPercent}</div>
|
||||||
|
<div
|
||||||
|
className={clsx('text-primary', large ? 'text-xl' : 'text-base')}
|
||||||
|
>
|
||||||
|
chance
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</Col>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
export function ContractDetails(props: { contract: Contract }) {
|
export function ContractDetails(props: { contract: Contract }) {
|
||||||
const { contract } = props
|
const { contract } = props
|
||||||
const { truePool, createdDate, resolvedDate } = compute(contract)
|
const { truePool, createdDate, resolvedDate } = compute(contract)
|
||||||
|
|
|
@ -14,7 +14,7 @@ import { Row } from './layout/row'
|
||||||
import dayjs from 'dayjs'
|
import dayjs from 'dayjs'
|
||||||
import { Linkify } from './linkify'
|
import { Linkify } from './linkify'
|
||||||
import clsx from 'clsx'
|
import clsx from 'clsx'
|
||||||
import { ContractDetails } from './contract-card'
|
import { ContractDetails, ResolutionOrChance } from './contract-card'
|
||||||
|
|
||||||
function ContractDescription(props: {
|
function ContractDescription(props: {
|
||||||
contract: Contract
|
contract: Contract
|
||||||
|
@ -84,40 +84,6 @@ function ContractDescription(props: {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
function ResolutionOrChance(props: {
|
|
||||||
resolution?: 'YES' | 'NO' | 'MKT' | 'CANCEL'
|
|
||||||
probPercent: string
|
|
||||||
className?: string
|
|
||||||
}) {
|
|
||||||
const { resolution, probPercent, className } = props
|
|
||||||
|
|
||||||
const resolutionColor = {
|
|
||||||
YES: 'text-primary',
|
|
||||||
NO: 'text-red-400',
|
|
||||||
MKT: 'text-blue-400',
|
|
||||||
CANCEL: 'text-yellow-400',
|
|
||||||
'': '', // Empty if unresolved
|
|
||||||
}[resolution || '']
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Col className={clsx('text-3xl md:text-4xl', className)}>
|
|
||||||
{resolution ? (
|
|
||||||
<>
|
|
||||||
<div className="text-lg md:text-xl text-gray-500">Resolved</div>
|
|
||||||
<div className={resolutionColor}>
|
|
||||||
{resolution === 'CANCEL' ? 'N/A' : resolution}
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<div className="text-primary">{probPercent}</div>
|
|
||||||
<div className="text-lg md:text-xl text-primary">chance</div>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
</Col>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
export const ContractOverview = (props: {
|
export const ContractOverview = (props: {
|
||||||
contract: Contract
|
contract: Contract
|
||||||
className?: string
|
className?: string
|
||||||
|
@ -141,6 +107,7 @@ export const ContractOverview = (props: {
|
||||||
className="md:hidden"
|
className="md:hidden"
|
||||||
resolution={resolution}
|
resolution={resolution}
|
||||||
probPercent={probPercent}
|
probPercent={probPercent}
|
||||||
|
large
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<ContractDetails contract={contract} />
|
<ContractDetails contract={contract} />
|
||||||
|
@ -150,6 +117,7 @@ export const ContractOverview = (props: {
|
||||||
className="hidden md:flex md:items-end"
|
className="hidden md:flex md:items-end"
|
||||||
resolution={resolution}
|
resolution={resolution}
|
||||||
probPercent={probPercent}
|
probPercent={probPercent}
|
||||||
|
large
|
||||||
/>
|
/>
|
||||||
</Row>
|
</Row>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user