From d6c7230d6a45d12287b455851ea465a44ebcc40f Mon Sep 17 00:00:00 2001 From: Boa Date: Tue, 26 Apr 2022 09:53:12 -0600 Subject: [PATCH] Moved answers (#102) * Moved answers * Remove unnecessary code --- web/components/answers/answers-panel.tsx | 45 ++++++++++++++++++++++++ web/components/feed/activity-items.ts | 36 ------------------- 2 files changed, 45 insertions(+), 36 deletions(-) diff --git a/web/components/answers/answers-panel.tsx b/web/components/answers/answers-panel.tsx index f7277618..3af2c286 100644 --- a/web/components/answers/answers-panel.tsx +++ b/web/components/answers/answers-panel.tsx @@ -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 @@ -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: {
No answers yet...
)} + {!resolveOption && sortedAnswers.length > 0 && ( + + )} + {tradingAllowed(contract) && (!resolveOption || resolveOption === 'CANCEL') && ( @@ -121,3 +137,32 @@ export function AnswersPanel(props: { ) } + +function getAnswers( + contract: FullContract, + 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) +} diff --git a/web/components/feed/activity-items.ts b/web/components/feed/activity-items.ts index 6c2d55fb..dd793407 100644 --- a/web/components/feed/activity-items.ts +++ b/web/components/feed/activity-items.ts @@ -256,38 +256,6 @@ function getAnswerGroups( return answerGroups } -function getAnswers( - contract: FullContract, - 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, bets, user) - ) } else { items.push( ...groupBetsAndComments(bets, comments, contract, user?.id, {