Moved answers ()

* Moved answers

* Remove unnecessary code
This commit is contained in:
Boa 2022-04-26 09:53:12 -06:00 committed by GitHub
parent 9fbd521732
commit d6c7230d6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 36 deletions
web/components

View File

@ -11,6 +11,11 @@ import { AnswerItem } from './answer-item'
import { CreateAnswerPanel } from './create-answer-panel'
import { AnswerResolvePanel } from './answer-resolve-panel'
import { Spacer } from '../layout/spacer'
import { FeedItems } from '../feed/feed-items'
import { ActivityItem } from '../feed/activity-items'
import { User } from '../../../common/user'
import { getOutcomeProbability } from '../../../common/calculate'
import { Answer } from '../../../common/answer'
export function AnswersPanel(props: {
contract: FullContract<DPM, FreeResponse>
@ -47,6 +52,8 @@ export function AnswersPanel(props: {
const chosenTotal = _.sum(Object.values(chosenAnswers))
const answerItems = getAnswers(contract, user)
const onChoose = (answerId: string, prob: number) => {
if (resolveOption === 'CHOOSE') {
setChosenAnswers({ [answerId]: prob })
@ -102,6 +109,15 @@ export function AnswersPanel(props: {
<div className="pb-4 text-gray-500">No answers yet...</div>
)}
{!resolveOption && sortedAnswers.length > 0 && (
<FeedItems
contract={contract}
items={answerItems}
className={''}
betRowClassName={''}
/>
)}
{tradingAllowed(contract) &&
(!resolveOption || resolveOption === 'CANCEL') && (
<CreateAnswerPanel contract={contract} />
@ -121,3 +137,32 @@ export function AnswersPanel(props: {
</Col>
)
}
function getAnswers(
contract: FullContract<DPM, FreeResponse>,
user: User | undefined | null
) {
const { answers } = contract
let outcomes = _.uniq(
answers.map((answer) => answer.number.toString())
).filter((outcome) => getOutcomeProbability(contract, outcome) > 0.0001)
outcomes = _.sortBy(outcomes, (outcome) =>
getOutcomeProbability(contract, outcome)
).reverse()
return outcomes
.map((outcome) => {
const answer = answers.find((answer) => answer.id === outcome) as Answer
//unnecessary
return {
id: outcome,
type: 'answer' as const,
contract,
answer,
items: [] as ActivityItem[],
user,
}
})
.filter((group) => group.answer)
}

View File

@ -256,38 +256,6 @@ function getAnswerGroups(
return answerGroups
}
function getAnswers(
contract: FullContract<DPM, FreeResponse>,
bets: Bet[],
user: User | undefined | null
) {
let outcomes = _.uniq(bets.map((bet) => bet.outcome)).filter(
(outcome) => getOutcomeProbability(contract, outcome) > 0.0001
)
outcomes = _.sortBy(outcomes, (outcome) =>
getOutcomeProbability(contract, outcome)
)
const answerGroups = outcomes
.map((outcome) => {
const answer = contract.answers?.find(
(answer) => answer.id === outcome
) as Answer
return {
id: outcome,
type: 'answer' as const,
contract,
answer,
items: [] as ActivityItem[],
user,
}
})
.filter((group) => group.answer)
return answerGroups
}
function groupBetsAndComments(
bets: Bet[],
comments: Comment[],
@ -387,10 +355,6 @@ export function getAllContractActivityItems(
commentsByBetId,
contract,
})
items.push(
...getAnswers(contract as FullContract<DPM, FreeResponse>, bets, user)
)
} else {
items.push(
...groupBetsAndComments(bets, comments, contract, user?.id, {