diff --git a/web/components/answers/answers-panel.tsx b/web/components/answers/answers-panel.tsx index 56b6a4ab..b06be4b8 100644 --- a/web/components/answers/answers-panel.tsx +++ b/web/components/answers/answers-panel.tsx @@ -1,7 +1,11 @@ import { sortBy, partition, sum } from 'lodash' import { useEffect, useState } from 'react' -import { FreeResponseContract, MultipleChoiceContract } from 'common/contract' +import { + Contract, + FreeResponseContract, + MultipleChoiceContract, +} from 'common/contract' import { Col } from '../layout/col' import { useUser } from 'web/hooks/use-user' import { getDpmOutcomeProbability } from 'common/calculate-dpm' @@ -29,11 +33,22 @@ import { ChatAlt2Icon, ChatAltIcon } from '@heroicons/react/solid' import { ChatIcon } from '@heroicons/react/outline' import { ReplyTo } from '../feed/feed-comments' +// TODO: get a color +// export function useAnswerColor(answer: Answer, contract:Contract) { +// const colorSortedAnswer = useChartAnswers(contract).map( +// (value, _index) => value.text +// ) +// colorIndex={colorSortedAnswer.indexOf(answer.text)} +// const color = +// colorIndex != undefined ? CATEGORY_COLORS[colorIndex] : '#B1B1C7' +// } + export function AnswersPanel(props: { contract: FreeResponseContract | MultipleChoiceContract + onAnswerCommentClick: (answer: Answer) => void }) { const isAdmin = useAdmin() - const { contract } = props + const { contract, onAnswerCommentClick } = props const { creatorId, resolution, resolutions, totalBets, outcomeType } = contract const [showAllAnswers, setShowAllAnswers] = useState(false) @@ -141,6 +156,7 @@ export function AnswersPanel(props: { answer={item} contract={contract} colorIndex={colorSortedAnswer.indexOf(item.text)} + onAnswerCommentClick={onAnswerCommentClick} /> ))} {hasZeroBetAnswers && !showAllAnswers && ( @@ -188,8 +204,9 @@ function OpenAnswer(props: { contract: FreeResponseContract | MultipleChoiceContract answer: Answer colorIndex: number | undefined + onAnswerCommentClick: (answer: Answer) => void }) { - const { answer, contract, colorIndex } = props + const { answer, contract, colorIndex, onAnswerCommentClick } = props const { username, avatarUrl, text } = answer const prob = getDpmOutcomeProbability(contract.totalShares, answer.id) const probPercent = formatPercent(prob) @@ -242,6 +259,7 @@ function OpenAnswer(props: { { + + + ) +} diff --git a/web/pages/[username]/[contractSlug].tsx b/web/pages/[username]/[contractSlug].tsx index 2fb02642..26bd6d1e 100644 --- a/web/pages/[username]/[contractSlug].tsx +++ b/web/pages/[username]/[contractSlug].tsx @@ -46,6 +46,8 @@ import { BetsSummary } from 'web/components/bet-summary' import { listAllComments } from 'web/lib/firebase/comments' import { ContractComment } from 'common/comment' import { ScrollToTopButton } from 'web/components/scroll-to-top-button' +import { Answer } from 'common/answer' +import { useEvent } from 'web/hooks/use-event' export const getStaticProps = fromPropz(getStaticPropz) export async function getStaticPropz(props: { @@ -204,6 +206,16 @@ export function ContractPageContent( contractId: contract.id, }) + const [answerResponse, setAnswerResponse] = useState( + undefined + ) + + const onAnswerCommentClick = useEvent((answer: Answer) => { + setAnswerResponse(answer) + }) + + const onCancelAnswerResponse = useEvent(() => setAnswerResponse(undefined)) + return ( - + )} @@ -283,6 +298,8 @@ export function ContractPageContent( bets={bets} userBets={userBets} comments={comments} + answerResponse={answerResponse} + onCancelAnswerResponse={onCancelAnswerResponse} /> {!isCreator && }