From d9c47e44268989ece0a37ed74cb3696a1906ea0a Mon Sep 17 00:00:00 2001 From: Marshall Polaris Date: Tue, 20 Sep 2022 21:12:53 -0700 Subject: [PATCH] Consolidate comment thread component code --- web/components/contract/contract-tabs.tsx | 147 +++++++++------------- 1 file changed, 56 insertions(+), 91 deletions(-) diff --git a/web/components/contract/contract-tabs.tsx b/web/components/contract/contract-tabs.tsx index 245a8d7d..caa5e5de 100644 --- a/web/components/contract/contract-tabs.tsx +++ b/web/components/contract/contract-tabs.tsx @@ -5,10 +5,9 @@ import { FeedBet } from '../feed/feed-bets' import { FeedLiquidity } from '../feed/feed-liquidity' import { FeedAnswerCommentGroup } from '../feed/feed-answer-comment-group' import { FeedCommentThread, ContractCommentInput } from '../feed/feed-comments' -import { CommentTipMap } from 'web/hooks/use-tip-txns' import { groupBy, sortBy } from 'lodash' import { Bet } from 'common/bet' -import { Contract, FreeResponseContract } from 'common/contract' +import { Contract } from 'common/contract' import { ContractComment } from 'common/comment' import { PAST_BETS, User } from 'common/user' import { ContractBetsTable, BetsSummary } from '../bets-list' @@ -92,35 +91,71 @@ const CommentsTabContent = memo(function CommentsTabContent(props: { const tips = useTipTxns({ contractId: contract.id }) const updatedComments = useComments(contract.id) ?? comments if (contract.outcomeType === 'FREE_RESPONSE') { + const generalComments = updatedComments.filter( + (c) => c.answerOutcome === undefined && c.betId === undefined + ) + const sortedAnswers = sortBy( + contract.answers, + (a) => -getOutcomeProbability(contract, a.id) + ) + const commentsByOutcome = groupBy( + comments, + (c) => c.answerOutcome ?? c.betOutcome ?? '_' + ) return ( <> - + {sortedAnswers.map((answer) => ( +
+
+ ))}
General Comments
- - comment.answerOutcome === undefined && - comment.betId === undefined - )} - tips={tips} - /> + + {generalComments.map((comment) => ( + + ))} ) } else { + const commentsByParent = groupBy(comments, (c) => c.replyToCommentId ?? '_') + const topLevelComments = commentsByParent['_'] ?? [] return ( - + <> + + {sortBy(topLevelComments, (c) => -c.createdTime).map((parent) => ( + c.createdTime + )} + tips={tips} + /> + ))} + ) } }) @@ -185,73 +220,3 @@ function ContractBetsActivity(props: { contract: Contract; bets: Bet[] }) { ) } - -function ContractCommentsActivity(props: { - contract: Contract - comments: ContractComment[] - tips: CommentTipMap -}) { - const { contract, comments, tips } = props - const commentsByParentId = groupBy(comments, (c) => c.replyToCommentId ?? '_') - const topLevelComments = sortBy( - commentsByParentId['_'] ?? [], - (c) => -c.createdTime - ) - - return ( - <> - - {topLevelComments.map((parent) => ( - c.createdTime - )} - tips={tips} - /> - ))} - - ) -} - -function FreeResponseContractCommentsActivity(props: { - contract: FreeResponseContract - comments: ContractComment[] - tips: CommentTipMap -}) { - const { contract, comments, tips } = props - - const sortedAnswers = sortBy( - contract.answers, - (answer) => -getOutcomeProbability(contract, answer.number.toString()) - ) - const commentsByOutcome = groupBy( - comments, - (c) => c.answerOutcome ?? c.betOutcome ?? '_' - ) - - return ( - <> - {sortedAnswers.map((answer) => ( -
-
- ))} - - ) -}