import { Answer } from 'common/answer' import { Contract, FreeResponseContract, MultipleChoiceContract, } from 'common/contract' import React, { useEffect, useRef, useState } from 'react' import { Col } from 'web/components/layout/col' import { Row } from 'web/components/layout/row' import { CopyLinkDateTimeComponent } from 'web/components/feed/copy-link-date-time' import { useRouter } from 'next/router' import { UserLink } from 'web/components/user-link' import { FeedCommentThread } from './feed-comments' import { AnswerCommentInput } from '../comment-input' import { ContractComment } from 'common/comment' import { Dictionary, sortBy } from 'lodash' import { getAnswerColor } from '../answers/answers-panel' import Curve from 'web/public/custom-components/curve' import { CommentTipMap } from 'web/hooks/use-tip-txns' import { useChartAnswers } from '../charts/contract/choice' export function CommentsAnswer(props: { answer: Answer contract: Contract color: string }) { const { answer, contract, color } = props const { username, name, text } = answer const answerElementId = `answer-${answer.id}` const { isReady, asPath } = useRouter() const [highlighted, setHighlighted] = useState(false) const answerRef = useRef(null) useEffect(() => { if (isReady && asPath.endsWith(`#${answerElementId}`)) { setHighlighted(true) } }, [isReady, asPath, answerElementId]) useEffect(() => { if (highlighted && answerRef.current) { answerRef.current.scrollIntoView(true) } }, [highlighted]) return (
answered
{text}
) } export function FreeResponseComments(props: { contract: FreeResponseContract | MultipleChoiceContract answerResponse: Answer | undefined onCancelAnswerResponse?: () => void topLevelComments: ContractComment[] commentsByParent: Dictionary<[ContractComment, ...ContractComment[]]> tips: CommentTipMap }) { const { contract, answerResponse, onCancelAnswerResponse, topLevelComments, commentsByParent, tips, } = props const answersArray = useChartAnswers(contract).map((answer) => answer.text) return ( <> {answerResponse && ( )} {topLevelComments.map((parent) => { if (parent.answerOutcome === undefined) { return ( c.createdTime )} tips={tips} /> ) } const answer = contract.answers.find( (answer) => answer.id === parent.answerOutcome ) if (answer === undefined) { console.error('Could not find answer that matches ID') return <> } const color = getAnswerColor(answer, answersArray) return ( <>
c.createdTime )} tips={tips} />
) })} ) }