Include top answer in answer card.
This commit is contained in:
parent
88b8d39c7c
commit
a6e6e2f52f
|
@ -1,9 +1,10 @@
|
||||||
import clsx from 'clsx'
|
import clsx from 'clsx'
|
||||||
import Link from 'next/link'
|
import Link from 'next/link'
|
||||||
|
import _ from 'lodash'
|
||||||
import { ClockIcon, DatabaseIcon, PencilIcon } from '@heroicons/react/outline'
|
import { ClockIcon, DatabaseIcon, PencilIcon } from '@heroicons/react/outline'
|
||||||
import { TrendingUpIcon } from '@heroicons/react/solid'
|
import { TrendingUpIcon } from '@heroicons/react/solid'
|
||||||
import { Row } from '../layout/row'
|
import { Row } from '../layout/row'
|
||||||
import { formatMoney } from '../../../common/util/format'
|
import { formatMoney, formatPercent } from '../../../common/util/format'
|
||||||
import { UserLink } from '../user-page'
|
import { UserLink } from '../user-page'
|
||||||
import {
|
import {
|
||||||
Contract,
|
Contract,
|
||||||
|
@ -30,9 +31,11 @@ import {
|
||||||
FullContract,
|
FullContract,
|
||||||
} from '../../../common/contract'
|
} from '../../../common/contract'
|
||||||
import {
|
import {
|
||||||
|
AnswerLabel,
|
||||||
BinaryContractOutcomeLabel,
|
BinaryContractOutcomeLabel,
|
||||||
FreeResponseOutcomeLabel,
|
FreeResponseOutcomeLabel,
|
||||||
} from '../outcome-label'
|
} from '../outcome-label'
|
||||||
|
import { getOutcomeProbability } from '../../../common/calculate'
|
||||||
|
|
||||||
export function ContractCard(props: {
|
export function ContractCard(props: {
|
||||||
contract: Contract
|
contract: Contract
|
||||||
|
@ -80,10 +83,9 @@ export function ContractCard(props: {
|
||||||
contract={contract}
|
contract={contract}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{outcomeType === 'FREE_RESPONSE' && resolution && (
|
{outcomeType === 'FREE_RESPONSE' && (
|
||||||
<FreeResponseResolution
|
<FreeResponseResolutionOrChance
|
||||||
contract={contract as FullContract<DPM, FreeResponse>}
|
contract={contract as FullContract<DPM, FreeResponse>}
|
||||||
resolution={resolution}
|
|
||||||
truncate="long"
|
truncate="long"
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
@ -130,20 +132,51 @@ export function BinaryResolutionOrChance(props: {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function FreeResponseResolution(props: {
|
function getTopAnswer(contract: FreeResponseContract) {
|
||||||
|
const { answers } = contract
|
||||||
|
const top = _.maxBy(
|
||||||
|
answers.map((answer) => ({
|
||||||
|
answer,
|
||||||
|
prob: getOutcomeProbability(contract, answer.id),
|
||||||
|
})),
|
||||||
|
({ prob }) => prob
|
||||||
|
)
|
||||||
|
return top?.answer
|
||||||
|
}
|
||||||
|
|
||||||
|
export function FreeResponseResolutionOrChance(props: {
|
||||||
contract: FreeResponseContract
|
contract: FreeResponseContract
|
||||||
resolution: string
|
|
||||||
truncate: 'short' | 'long' | 'none'
|
truncate: 'short' | 'long' | 'none'
|
||||||
}) {
|
}) {
|
||||||
const { contract, resolution, truncate } = props
|
const { contract, truncate } = props
|
||||||
|
const { resolution } = contract
|
||||||
|
|
||||||
|
const topAnswer = getTopAnswer(contract)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Col className="text-xl">
|
<Col className="text-xl">
|
||||||
|
{resolution ? (
|
||||||
|
<>
|
||||||
<div className={clsx('text-base text-gray-500')}>Resolved</div>
|
<div className={clsx('text-base text-gray-500')}>Resolved</div>
|
||||||
<FreeResponseOutcomeLabel
|
<FreeResponseOutcomeLabel
|
||||||
contract={contract}
|
contract={contract}
|
||||||
resolution={resolution}
|
resolution={resolution}
|
||||||
truncate={truncate}
|
truncate={truncate}
|
||||||
/>
|
/>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
topAnswer && (
|
||||||
|
<Row className="flex-1 items-center justify-between gap-6">
|
||||||
|
<AnswerLabel answer={topAnswer} truncate={truncate} />
|
||||||
|
<Col className="text-primary">
|
||||||
|
<div>
|
||||||
|
{formatPercent(getOutcomeProbability(contract, topAnswer.id))}
|
||||||
|
</div>
|
||||||
|
<div className="text-base">chance</div>
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
|
)
|
||||||
|
)}
|
||||||
</Col>
|
</Col>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@ import { Row } from '../layout/row'
|
||||||
import { Linkify } from '../linkify'
|
import { Linkify } from '../linkify'
|
||||||
import clsx from 'clsx'
|
import clsx from 'clsx'
|
||||||
import {
|
import {
|
||||||
FreeResponseResolution,
|
FreeResponseResolutionOrChance,
|
||||||
ContractDetails,
|
ContractDetails,
|
||||||
BinaryResolutionOrChance,
|
BinaryResolutionOrChance,
|
||||||
} from './contract-card'
|
} from './contract-card'
|
||||||
|
@ -59,9 +59,8 @@ export const ContractOverview = (props: {
|
||||||
) : (
|
) : (
|
||||||
outcomeType === 'FREE_RESPONSE' &&
|
outcomeType === 'FREE_RESPONSE' &&
|
||||||
resolution && (
|
resolution && (
|
||||||
<FreeResponseResolution
|
<FreeResponseResolutionOrChance
|
||||||
contract={contract}
|
contract={contract}
|
||||||
resolution={resolution}
|
|
||||||
truncate="none"
|
truncate="none"
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
|
|
|
@ -10,7 +10,7 @@ import { AnswersGraph } from '../../../components/answers/answers-graph'
|
||||||
import {
|
import {
|
||||||
BinaryResolutionOrChance,
|
BinaryResolutionOrChance,
|
||||||
ContractDetails,
|
ContractDetails,
|
||||||
FreeResponseResolution,
|
FreeResponseResolutionOrChance,
|
||||||
} from '../../../components/contract/contract-card'
|
} from '../../../components/contract/contract-card'
|
||||||
import { ContractProbGraph } from '../../../components/contract/contract-prob-graph'
|
import { ContractProbGraph } from '../../../components/contract/contract-prob-graph'
|
||||||
import { Col } from '../../../components/layout/col'
|
import { Col } from '../../../components/layout/col'
|
||||||
|
@ -122,9 +122,8 @@ function ContractEmbed(props: { contract: Contract; bets: Bet[] }) {
|
||||||
{isBinary && <BinaryResolutionOrChance contract={contract} />}
|
{isBinary && <BinaryResolutionOrChance contract={contract} />}
|
||||||
|
|
||||||
{outcomeType === 'FREE_RESPONSE' && resolution && (
|
{outcomeType === 'FREE_RESPONSE' && resolution && (
|
||||||
<FreeResponseResolution
|
<FreeResponseResolutionOrChance
|
||||||
contract={contract}
|
contract={contract}
|
||||||
resolution={resolution}
|
|
||||||
truncate="long"
|
truncate="long"
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user