import { FreeResponse, FullContract } from 'common/contract' import { Answer } from 'common/answer' import { ActivityItem } from 'web/components/feed/activity-items' import { Bet } from 'common/bet' import { Comment } from 'common/comment' import { useUser } from 'web/hooks/use-user' import { getDpmOutcomeProbability } from 'common/calculate-dpm' import { formatPercent } from 'common/util/format' import React, { useEffect, useState } from 'react' import { Col } from 'web/components/layout/col' import { Modal } from 'web/components/layout/modal' import { AnswerBetPanel } from 'web/components/answers/answer-bet-panel' import { Row } from 'web/components/layout/row' import { Avatar } from 'web/components/avatar' import { UserLink } from 'web/components/user-page' import { Linkify } from 'web/components/linkify' import clsx from 'clsx' import { tradingAllowed } from 'web/lib/firebase/contracts' import { BuyButton } from 'web/components/yes-no-selector' import { FeedItem } from 'web/components/feed/feed-items' import { CommentInput, getMostRecentCommentableBet, } from 'web/components/feed/feed-comments' import { CopyLinkDateTimeComponent } from 'web/components/feed/copy-link-date-time' import { useRouter } from 'next/router' export function FeedAnswerCommentGroup(props: { contract: FullContract answer: Answer items: ActivityItem[] type: string betsByCurrentUser?: Bet[] commentsByCurrentUser?: Comment[] }) { const { answer, items, contract, betsByCurrentUser, commentsByCurrentUser } = props const { username, avatarUrl, name, text } = answer const answerElementId = `answer-${answer.id}` const user = useUser() const mostRecentCommentableBet = getMostRecentCommentableBet( betsByCurrentUser ?? [], commentsByCurrentUser ?? [], 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 = !!commentsByCurrentUser 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]) const [highlighted, setHighlighted] = useState(false) const router = useRouter() useEffect(() => { if (router.asPath.endsWith(`#${answerElementId}`)) { setHighlighted(true) } }, [answerElementId, router.asPath]) return ( setOpen(false)} className="sm:max-w-84 !rounded-md bg-white !px-8 !py-6" isModal={true} />
answered
{isFreeResponseContractPage && (
)}
{probPercent} setOpen(true)} />
{isFreeResponseContractPage && ( )}
{items.map((item, index) => (
{index !== items.length - 1 ? (
))} {showReply && (
)} ) }