Render free response comment threads more simply without bets (#893)

This commit is contained in:
Marshall Polaris 2022-09-18 19:16:48 -07:00 committed by GitHub
parent 58dcbaaf6e
commit a9e5020904
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 20 deletions

View File

@ -75,7 +75,9 @@ export function ContractTabs(props: {
<> <>
<FreeResponseContractCommentsActivity <FreeResponseContractCommentsActivity
contract={contract} contract={contract}
bets={visibleBets} betsByCurrentUser={
user ? visibleBets.filter((b) => b.userId === user.id) : []
}
comments={comments} comments={comments}
tips={tips} tips={tips}
user={user} user={user}

View File

@ -1,7 +1,6 @@
import { useState } from 'react' import { useState } from 'react'
import { Contract, FreeResponseContract } from 'common/contract' import { Contract, FreeResponseContract } from 'common/contract'
import { ContractComment } from 'common/comment' import { ContractComment } from 'common/comment'
import { Answer } from 'common/answer'
import { Bet } from 'common/bet' import { Bet } from 'common/bet'
import { getOutcomeProbability } from 'common/calculate' import { getOutcomeProbability } from 'common/calculate'
import { Pagination } from 'web/components/pagination' import { Pagination } from 'web/components/pagination'
@ -12,7 +11,7 @@ import { FeedCommentThread, ContractCommentInput } from './feed-comments'
import { User } from 'common/user' import { User } from 'common/user'
import { CommentTipMap } from 'web/hooks/use-tip-txns' import { CommentTipMap } from 'web/hooks/use-tip-txns'
import { LiquidityProvision } from 'common/liquidity-provision' import { LiquidityProvision } from 'common/liquidity-provision'
import { groupBy, sortBy, uniq } from 'lodash' import { groupBy, sortBy } from 'lodash'
import { Col } from 'web/components/layout/col' import { Col } from 'web/components/layout/col'
export function ContractBetsActivity(props: { export function ContractBetsActivity(props: {
@ -115,34 +114,23 @@ export function ContractCommentsActivity(props: {
export function FreeResponseContractCommentsActivity(props: { export function FreeResponseContractCommentsActivity(props: {
contract: FreeResponseContract contract: FreeResponseContract
bets: Bet[] betsByCurrentUser: Bet[]
comments: ContractComment[] comments: ContractComment[]
tips: CommentTipMap tips: CommentTipMap
user: User | null | undefined 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)) const sortedAnswers = sortBy(
outcomes = sortBy( contract.answers,
outcomes, (answer) => -getOutcomeProbability(contract, answer.number.toString())
(outcome) => -getOutcomeProbability(contract, outcome)
) )
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 commentsByUserId = groupBy(comments, (c) => c.userId)
const commentsByOutcome = groupBy(comments, (c) => c.answerOutcome ?? '_') const commentsByOutcome = groupBy(comments, (c) => c.answerOutcome ?? '_')
return ( return (
<> <>
{answers.map((answer) => ( {sortedAnswers.map((answer) => (
<div key={answer.id} className={'relative pb-4'}> <div key={answer.id} className={'relative pb-4'}>
<span <span
className="absolute top-5 left-5 -ml-px h-[calc(100%-2rem)] w-0.5 bg-gray-200" className="absolute top-5 left-5 -ml-px h-[calc(100%-2rem)] w-0.5 bg-gray-200"