{isSelf ? 'You' : bettor ? bettor.name : 'A trader'} {bought}{' '}
{money}
- {!hideOutcome && (
+ {contract.outcomeType !== 'FREE_RESPONSE' && (
<>
{' '}
of{' '}
@@ -581,6 +692,32 @@ export function FeedQuestion(props: {
)
}
+function getMostRecentCommentableBet(
+ betsByCurrentUser: Bet[],
+ comments: Comment[],
+ user?: User | null,
+ answerOutcome?: string
+) {
+ return betsByCurrentUser
+ .filter((bet) => {
+ if (
+ canCommentOnBet(bet, user) &&
+ // The bet doesn't already have a comment
+ !comments.some((comment) => comment.betId == bet.id)
+ ) {
+ if (!answerOutcome) return true
+ // If we're in free response, don't allow commenting on ante bet
+ return (
+ bet.outcome !== GENERAL_COMMENTS_OUTCOME_ID &&
+ answerOutcome === bet.outcome
+ )
+ }
+ return false
+ })
+ .sort((b1, b2) => b1.createdTime - b2.createdTime)
+ .pop()
+}
+
function canCommentOnBet(bet: Bet, user?: User | null) {
const { userId, createdTime, isRedemption } = bet
const isSelf = user?.id === userId
@@ -768,13 +905,35 @@ function FeedAnswerGroup(props: {
answer: Answer
items: ActivityItem[]
type: string
+ betsByCurrentUser?: Bet[]
+ comments?: Comment[]
}) {
- const { answer, items, contract, type } = props
+ const { answer, items, contract, type, betsByCurrentUser, comments } = props
const { username, avatarUrl, name, text } = answer
-
+ const user = useUser()
+ const mostRecentCommentableBet = getMostRecentCommentableBet(
+ betsByCurrentUser ?? [],
+ comments ?? [],
+ user,
+ answer.number + ''
+ )
const prob = getDpmOutcomeProbability(contract.totalShares, answer.id)
const probPercent = formatPercent(prob)
const [open, setOpen] = useState(false)
+ const [showReply, setShowReply] = useState(false)
+ const isFreeResponseContractPage = type === 'answergroup' && comments
+ if (mostRecentCommentableBet && !showReply) setShowReplyAndFocus(true)
+ const [inputRef, setInputRef] = useState
(null)
+
+ // If they've already opened the input box, focus it once again
+ function setShowReplyAndFocus(show: boolean) {
+ setShowReply(show)
+ inputRef?.focus()
+ }
+
+ useEffect(() => {
+ if (showReply && inputRef) inputRef.focus()
+ }, [inputRef, showReply])
return (
-