multi choice market page

This commit is contained in:
mantikoros 2022-07-27 18:05:52 -07:00
parent 3aa22a7772
commit adba5135e2
9 changed files with 33 additions and 24 deletions

View File

@ -23,6 +23,7 @@ import {
BinaryContract,
FreeResponseContract,
PseudoNumericContract,
MultipleChoiceContract,
} from './contract'
import { floatingEqual } from './util/math'
@ -200,7 +201,9 @@ export function getContractBetNullMetrics() {
}
}
export function getTopAnswer(contract: FreeResponseContract) {
export function getTopAnswer(
contract: FreeResponseContract | MultipleChoiceContract
) {
const { answers } = contract
const top = maxBy(
answers?.map((answer) => ({

View File

@ -3,7 +3,7 @@ import { useEffect, useRef, useState } from 'react'
import { XIcon } from '@heroicons/react/solid'
import { Answer } from 'common/answer'
import { FreeResponseContract } from 'common/contract'
import { FreeResponseContract, MultipleChoiceContract } from 'common/contract'
import { BuyAmountInput } from '../amount-input'
import { Col } from '../layout/col'
import { APIError, placeBet } from 'web/lib/firebase/api'
@ -29,7 +29,7 @@ import { isIOS } from 'web/lib/util/device'
export function AnswerBetPanel(props: {
answer: Answer
contract: FreeResponseContract
contract: FreeResponseContract | MultipleChoiceContract
closePanel: () => void
className?: string
isModal?: boolean

View File

@ -1,7 +1,7 @@
import clsx from 'clsx'
import { Answer } from 'common/answer'
import { FreeResponseContract } from 'common/contract'
import { FreeResponseContract, MultipleChoiceContract } from 'common/contract'
import { Col } from '../layout/col'
import { Row } from '../layout/row'
import { Avatar } from '../avatar'
@ -13,7 +13,7 @@ import { Linkify } from '../linkify'
export function AnswerItem(props: {
answer: Answer
contract: FreeResponseContract
contract: FreeResponseContract | MultipleChoiceContract
showChoice: 'radio' | 'checkbox' | undefined
chosenProb: number | undefined
totalChosenProb?: number

View File

@ -2,7 +2,7 @@ import clsx from 'clsx'
import { sum } from 'lodash'
import { useState } from 'react'
import { Contract, FreeResponse } from 'common/contract'
import { FreeResponseContract, MultipleChoiceContract } from 'common/contract'
import { Col } from '../layout/col'
import { APIError, resolveMarket } from 'web/lib/firebase/api'
import { Row } from '../layout/row'
@ -11,7 +11,7 @@ import { ResolveConfirmationButton } from '../confirmation-button'
import { removeUndefinedProps } from 'common/util/object'
export function AnswerResolvePanel(props: {
contract: Contract & FreeResponse
contract: FreeResponseContract | MultipleChoiceContract
resolveOption: 'CHOOSE' | 'CHOOSE_MULTIPLE' | 'CANCEL' | undefined
setResolveOption: (
option: 'CHOOSE' | 'CHOOSE_MULTIPLE' | 'CANCEL' | undefined

View File

@ -5,14 +5,14 @@ import { groupBy, sortBy, sumBy } from 'lodash'
import { memo } from 'react'
import { Bet } from 'common/bet'
import { FreeResponseContract } from 'common/contract'
import { FreeResponseContract, MultipleChoiceContract } from 'common/contract'
import { getOutcomeProbability } from 'common/calculate'
import { useWindowSize } from 'web/hooks/use-window-size'
const NUM_LINES = 6
export const AnswersGraph = memo(function AnswersGraph(props: {
contract: FreeResponseContract
contract: FreeResponseContract | MultipleChoiceContract
bets: Bet[]
height?: number
}) {
@ -178,7 +178,7 @@ function formatTime(
return d.format(format)
}
const computeProbsByOutcome = (bets: Bet[], contract: FreeResponseContract) => {
const computeProbsByOutcome = (bets: Bet[], contract: FreeResponseContract | MultipleChoiceContract) => {
const { totalBets } = contract
const betsByOutcome = groupBy(bets, (bet) => bet.outcome)

View File

@ -1,7 +1,7 @@
import { sortBy, partition, sum, uniq } from 'lodash'
import { useEffect, useState } from 'react'
import { FreeResponseContract } from 'common/contract'
import { FreeResponseContract, MultipleChoiceContract } from 'common/contract'
import { Col } from '../layout/col'
import { useUser } from 'web/hooks/use-user'
import { getDpmOutcomeProbability } from 'common/calculate-dpm'
@ -25,9 +25,12 @@ import { UserLink } from 'web/components/user-page'
import { Linkify } from 'web/components/linkify'
import { BuyButton } from 'web/components/yes-no-selector'
export function AnswersPanel(props: { contract: FreeResponseContract }) {
export function AnswersPanel(props: {
contract: FreeResponseContract | MultipleChoiceContract
}) {
const { contract } = props
const { creatorId, resolution, resolutions, totalBets } = contract
const { creatorId, resolution, resolutions, totalBets, outcomeType } =
contract
const answers = useAnswers(contract.id) ?? contract.answers
const [winningAnswers, losingAnswers] = partition(
@ -131,7 +134,8 @@ export function AnswersPanel(props: { contract: FreeResponseContract }) {
<div className="pb-4 text-gray-500">No answers yet...</div>
)}
{tradingAllowed(contract) &&
{outcomeType === 'FREE_RESPONSE' &&
tradingAllowed(contract) &&
(!resolveOption || resolveOption === 'CANCEL') && (
<CreateAnswerPanel contract={contract} />
)}
@ -152,7 +156,7 @@ export function AnswersPanel(props: { contract: FreeResponseContract }) {
}
function getAnswerItems(
contract: FreeResponseContract,
contract: FreeResponseContract | MultipleChoiceContract,
answers: Answer[],
user: User | undefined | null
) {
@ -178,7 +182,7 @@ function getAnswerItems(
}
function OpenAnswer(props: {
contract: FreeResponseContract
contract: FreeResponseContract | MultipleChoiceContract
answer: Answer
items: ActivityItem[]
type: string

View File

@ -8,6 +8,7 @@ import {
BinaryContract,
Contract,
FreeResponseContract,
MultipleChoiceContract,
NumericContract,
PseudoNumericContract,
} from 'common/contract'
@ -227,7 +228,7 @@ function FreeResponseTopAnswer(props: {
}
export function FreeResponseResolutionOrChance(props: {
contract: FreeResponseContract
contract: FreeResponseContract | MultipleChoiceContract
truncate: 'short' | 'long' | 'none'
className?: string
}) {

View File

@ -85,13 +85,13 @@ export const ContractOverview = (props: {
{tradingAllowed(contract) && <BetRow contract={contract} />}
</Row>
) : (
outcomeType === 'FREE_RESPONSE' &&
resolution && (
outcomeType === 'FREE_RESPONSE' ||
(outcomeType === 'MULTIPLE_CHOICE' && resolution && (
<FreeResponseResolutionOrChance
contract={contract}
truncate="none"
/>
)
))
)}
{outcomeType === 'NUMERIC' && (
@ -110,9 +110,10 @@ export const ContractOverview = (props: {
{(isBinary || isPseudoNumeric) && (
<ContractProbGraph contract={contract} bets={bets} />
)}{' '}
{outcomeType === 'FREE_RESPONSE' && (
<AnswersGraph contract={contract} bets={bets} />
)}
{outcomeType === 'FREE_RESPONSE' ||
(outcomeType === 'MULTIPLE_CHOICE' && (
<AnswersGraph contract={contract} bets={bets} />
))}
{outcomeType === 'NUMERIC' && <NumericGraph contract={contract} />}
{(contract.description || isCreator) && <Spacer h={6} />}
{isCreator && <ShareMarket className="px-2" contract={contract} />}

View File

@ -217,7 +217,7 @@ export function ContractPageContent(
/>
)}
{outcomeType === 'FREE_RESPONSE' && (
{outcomeType === 'FREE_RESPONSE' || outcomeType === 'MULTIPLE_CHOICE' && (
<>
<Spacer h={4} />
<AnswersPanel contract={contract} />