From a9e5020904f8356f95356b7cf9c68979b70c72d7 Mon Sep 17 00:00:00 2001 From: Marshall Polaris Date: Sun, 18 Sep 2022 19:16:48 -0700 Subject: [PATCH] Render free response comment threads more simply without bets (#893) --- web/components/contract/contract-tabs.tsx | 4 +++- web/components/feed/contract-activity.tsx | 26 ++++++----------------- 2 files changed, 10 insertions(+), 20 deletions(-) diff --git a/web/components/contract/contract-tabs.tsx b/web/components/contract/contract-tabs.tsx index 939eb624..b5895f60 100644 --- a/web/components/contract/contract-tabs.tsx +++ b/web/components/contract/contract-tabs.tsx @@ -75,7 +75,9 @@ export function ContractTabs(props: { <> b.userId === user.id) : [] + } comments={comments} tips={tips} user={user} diff --git a/web/components/feed/contract-activity.tsx b/web/components/feed/contract-activity.tsx index b7789308..fc817082 100644 --- a/web/components/feed/contract-activity.tsx +++ b/web/components/feed/contract-activity.tsx @@ -1,7 +1,6 @@ import { useState } from 'react' import { Contract, FreeResponseContract } from 'common/contract' import { ContractComment } from 'common/comment' -import { Answer } from 'common/answer' import { Bet } from 'common/bet' import { getOutcomeProbability } from 'common/calculate' import { Pagination } from 'web/components/pagination' @@ -12,7 +11,7 @@ import { FeedCommentThread, ContractCommentInput } from './feed-comments' import { User } from 'common/user' import { CommentTipMap } from 'web/hooks/use-tip-txns' import { LiquidityProvision } from 'common/liquidity-provision' -import { groupBy, sortBy, uniq } from 'lodash' +import { groupBy, sortBy } from 'lodash' import { Col } from 'web/components/layout/col' export function ContractBetsActivity(props: { @@ -115,34 +114,23 @@ export function ContractCommentsActivity(props: { export function FreeResponseContractCommentsActivity(props: { contract: FreeResponseContract - bets: Bet[] + betsByCurrentUser: Bet[] comments: ContractComment[] tips: CommentTipMap user: User | null | undefined }) { - const { bets, contract, comments, user, tips } = props + const { betsByCurrentUser, contract, comments, user, tips } = props - let outcomes = uniq(bets.map((bet) => bet.outcome)) - outcomes = sortBy( - outcomes, - (outcome) => -getOutcomeProbability(contract, outcome) + const sortedAnswers = sortBy( + contract.answers, + (answer) => -getOutcomeProbability(contract, answer.number.toString()) ) - - const answers = outcomes - .map((outcome) => { - return contract.answers.find((answer) => answer.id === outcome) as Answer - }) - .filter((answer) => answer != null) - - const betsByCurrentUser = user - ? bets.filter((bet) => bet.userId === user.id) - : [] const commentsByUserId = groupBy(comments, (c) => c.userId) const commentsByOutcome = groupBy(comments, (c) => c.answerOutcome ?? '_') return ( <> - {answers.map((answer) => ( + {sortedAnswers.map((answer) => (