FR answer group: Choose one outcome for having a comment

This commit is contained in:
James Grugett 2022-03-14 16:39:59 -05:00
parent f2d26b631d
commit 5524889d48

View File

@ -6,7 +6,6 @@ import { getOutcomeProbability } from '../../../common/calculate'
import { Comment } from '../../../common/comment' import { Comment } from '../../../common/comment'
import { Contract } from '../../../common/contract' import { Contract } from '../../../common/contract'
import { User } from '../../../common/user' import { User } from '../../../common/user'
import { filterDefined } from '../../../common/util/array'
import { mapCommentsByBetId } from '../../lib/firebase/comments' import { mapCommentsByBetId } from '../../lib/firebase/comments'
export type ActivityItem = export type ActivityItem =
@ -173,12 +172,29 @@ function getAnswerGroups(
let outcomes = _.uniq(bets.map((bet) => bet.outcome)).filter( let outcomes = _.uniq(bets.map((bet) => bet.outcome)).filter(
(outcome) => getOutcomeProbability(contract.totalShares, outcome) > 0.01 (outcome) => getOutcomeProbability(contract.totalShares, outcome) > 0.01
) )
if (abbreviated) outcomes = outcomes.slice(-2) if (abbreviated) {
const lastComment = _.last(comments)
const lastCommentOutcome = bets.find(
(bet) => bet.id === lastComment?.betId
)?.outcome
if (lastCommentOutcome) {
outcomes = [
...outcomes.filter((outcome) => outcome !== lastCommentOutcome),
lastCommentOutcome,
]
}
outcomes = outcomes.slice(-2)
}
if (sortByProb) { if (sortByProb) {
outcomes = _.sortBy( outcomes = _.sortBy(
outcomes, outcomes,
(outcome) => -1 * getOutcomeProbability(contract.totalShares, outcome) (outcome) => -1 * getOutcomeProbability(contract.totalShares, outcome)
) )
} else {
// Sort by recent bet.
outcomes = _.sortBy(outcomes, (outcome) =>
_.findLastIndex(bets, (bet) => bet.outcome === outcome)
)
} }
const answerGroups = outcomes const answerGroups = outcomes
@ -285,7 +301,7 @@ export function getRecentContractActivityItems(
showDescription: false, showDescription: false,
} }
const answerItems = const items =
contract.outcomeType === 'FREE_RESPONSE' contract.outcomeType === 'FREE_RESPONSE'
? getAnswerGroups(contract, bets, comments, user, { ? getAnswerGroups(contract, bets, comments, user, {
sortByProb: false, sortByProb: false,
@ -296,5 +312,5 @@ export function getRecentContractActivityItems(
abbreviated: true, abbreviated: true,
}) })
return [questionItem, ...answerItems] return [questionItem, ...items]
} }