diff --git a/functions/.gitignore b/functions/.gitignore index b4eba650..7aeaedd4 100644 --- a/functions/.gitignore +++ b/functions/.gitignore @@ -16,4 +16,4 @@ package-lock.json ui-debug.log firebase-debug.log firestore-debug.log -firestore_export/ \ No newline at end of file +firestore_export/ diff --git a/web/components/feed/activity-items.ts b/web/components/feed/activity-items.ts index ceb9fe58..6c2d55fb 100644 --- a/web/components/feed/activity-items.ts +++ b/web/components/feed/activity-items.ts @@ -68,7 +68,7 @@ export type BetGroupItem = BaseActivityItem & { } export type AnswerGroupItem = BaseActivityItem & { - type: 'answergroup' + type: 'answergroup' | 'answer' answer: Answer items: ActivityItem[] } @@ -256,6 +256,38 @@ 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[], @@ -328,19 +360,37 @@ export function getAllContractActivityItems( : [{ type: 'description', id: '0', contract }] if (outcomeType === 'FREE_RESPONSE') { + const onlyUsersBetsOrBetsWithComments = bets.filter((bet) => + comments.some( + (comment) => comment.betId === bet.id || bet.userId === user?.id + ) + ) items.push( - ...getAnswerGroups( - contract as FullContract, - bets, + ...groupBetsAndComments( + onlyUsersBetsOrBetsWithComments, comments, - user, + contract, + user?.id, { - sortByProb: true, + hideOutcome: false, abbreviated, + smallAvatar: false, reversed, } ) ) + const commentsByBetId = mapCommentsByBetId(comments) + items.push({ + type: 'commentInput', + id: 'commentInput', + bets, + commentsByBetId, + contract, + }) + + items.push( + ...getAnswers(contract as FullContract, bets, user) + ) } else { items.push( ...groupBetsAndComments(bets, comments, contract, user?.id, { @@ -359,14 +409,16 @@ export function getAllContractActivityItems( items.push({ type: 'resolve', id: `${contract.resolutionTime}`, contract }) } - const commentsByBetId = mapCommentsByBetId(comments) - items.push({ - type: 'commentInput', - id: 'commentInput', - bets, - commentsByBetId, - contract, - }) + if (outcomeType === 'BINARY') { + const commentsByBetId = mapCommentsByBetId(comments) + items.push({ + type: 'commentInput', + id: 'commentInput', + bets, + commentsByBetId, + contract, + }) + } if (reversed) items.reverse() diff --git a/web/components/feed/feed-items.tsx b/web/components/feed/feed-items.tsx index c865b617..f9dc9ac7 100644 --- a/web/components/feed/feed-items.tsx +++ b/web/components/feed/feed-items.tsx @@ -1,5 +1,5 @@ // From https://tailwindui.com/components/application-ui/lists/feeds -import { Fragment, useRef, useState } from 'react' +import React, { Fragment, useRef, useState } from 'react' import * as _ from 'lodash' import { BanIcon, @@ -67,7 +67,12 @@ export function FeedItems(props: {
{items.map((item, activityItemIdx) => ( -
+
{activityItemIdx !== items.length - 1 || item.type === 'answergroup' ? ( case 'answergroup': return + case 'answer': + return case 'close': return case 'resolve': @@ -195,10 +202,6 @@ export function CommentInput(props: { const user = useUser() const [comment, setComment] = useState('') - if (outcomeType === 'FREE_RESPONSE') { - return
- } - let canCommentOnABet = false bets.some((bet) => { // make sure there is not already a comment with a matching bet id: @@ -224,34 +227,38 @@ export function CommentInput(props: { return ( <> -
- -
-
-
-
-