Clean up FR answer on card

This commit is contained in:
James Grugett 2022-04-19 22:31:41 -05:00
parent 30d92becd6
commit 3b413e52e5
2 changed files with 26 additions and 10 deletions

View File

@ -68,7 +68,7 @@ export function ContractCard(props: {
<Row <Row
className={clsx( className={clsx(
'justify-between gap-4', 'justify-between gap-4',
outcomeType === 'FREE_RESPONSE' && 'flex-col items-start' outcomeType === 'FREE_RESPONSE' && 'flex-col items-start !gap-2'
)} )}
> >
<p <p
@ -85,6 +85,7 @@ export function ContractCard(props: {
)} )}
{outcomeType === 'FREE_RESPONSE' && ( {outcomeType === 'FREE_RESPONSE' && (
<FreeResponseResolutionOrChance <FreeResponseResolutionOrChance
className="self-end text-gray-600"
contract={contract as FullContract<DPM, FreeResponse>} contract={contract as FullContract<DPM, FreeResponse>}
truncate="long" truncate="long"
/> />
@ -147,14 +148,15 @@ function getTopAnswer(contract: FreeResponseContract) {
export function FreeResponseResolutionOrChance(props: { export function FreeResponseResolutionOrChance(props: {
contract: FreeResponseContract contract: FreeResponseContract
truncate: 'short' | 'long' | 'none' truncate: 'short' | 'long' | 'none'
className?: string
}) { }) {
const { contract, truncate } = props const { contract, truncate, className } = props
const { resolution } = contract const { resolution } = contract
const topAnswer = getTopAnswer(contract) const topAnswer = getTopAnswer(contract)
return ( return (
<Col className="text-xl"> <Col className={clsx(resolution ? 'text-3xl' : 'text-xl', className)}>
{resolution ? ( {resolution ? (
<> <>
<div className={clsx('text-base text-gray-500')}>Resolved</div> <div className={clsx('text-base text-gray-500')}>Resolved</div>
@ -162,13 +164,18 @@ export function FreeResponseResolutionOrChance(props: {
contract={contract} contract={contract}
resolution={resolution} resolution={resolution}
truncate={truncate} truncate={truncate}
answerClassName="text-xl"
/> />
</> </>
) : ( ) : (
topAnswer && ( topAnswer && (
<Row className="flex-1 items-center justify-between gap-6"> <Row className="items-center gap-6">
<AnswerLabel answer={topAnswer} truncate={truncate} /> <AnswerLabel
<Col className="text-primary"> className="!text-gray-600"
answer={topAnswer}
truncate={truncate}
/>
<Col className="text-primary text-3xl">
<div> <div>
{formatPercent(getOutcomeProbability(contract, topAnswer.id))} {formatPercent(getOutcomeProbability(contract, topAnswer.id))}
</div> </div>

View File

@ -1,3 +1,4 @@
import clsx from 'clsx'
import { Answer } from '../../common/answer' import { Answer } from '../../common/answer'
import { getProbability } from '../../common/calculate' import { getProbability } from '../../common/calculate'
import { import {
@ -59,8 +60,9 @@ export function FreeResponseOutcomeLabel(props: {
contract: FreeResponseContract contract: FreeResponseContract
resolution: string | 'CANCEL' | 'MKT' resolution: string | 'CANCEL' | 'MKT'
truncate: 'short' | 'long' | 'none' truncate: 'short' | 'long' | 'none'
answerClassName?: string
}) { }) {
const { contract, resolution, truncate } = props const { contract, resolution, truncate, answerClassName } = props
if (resolution === 'CANCEL') return <CancelLabel /> if (resolution === 'CANCEL') return <CancelLabel />
if (resolution === 'MKT') return <MultiLabel /> if (resolution === 'MKT') return <MultiLabel />
@ -68,7 +70,13 @@ export function FreeResponseOutcomeLabel(props: {
const { answers } = contract const { answers } = contract
const chosen = answers?.find((answer) => answer.id === resolution) const chosen = answers?.find((answer) => answer.id === resolution)
if (!chosen) return <AnswerNumberLabel number={resolution} /> if (!chosen) return <AnswerNumberLabel number={resolution} />
return <AnswerLabel answer={chosen} truncate={truncate} /> return (
<AnswerLabel
answer={chosen}
truncate={truncate}
className={answerClassName}
/>
)
} }
export function YesLabel() { export function YesLabel() {
@ -103,8 +111,9 @@ export function AnswerNumberLabel(props: { number: string }) {
export function AnswerLabel(props: { export function AnswerLabel(props: {
answer: Answer answer: Answer
truncate: 'short' | 'long' | 'none' truncate: 'short' | 'long' | 'none'
className?: string
}) { }) {
const { answer, truncate } = props const { answer, truncate, className } = props
const { text } = answer const { text } = answer
let truncated = text let truncated = text
@ -114,5 +123,5 @@ export function AnswerLabel(props: {
truncated = text.slice(0, 75) + '...' truncated = text.slice(0, 75) + '...'
} }
return <span className="text-primary">{truncated}</span> return <span className={className}>{truncated}</span>
} }