// From https://tailwindui.com/components/application-ui/lists/feeds import React, { Fragment, useRef, useState } from 'react' import * as _ from 'lodash' import { BanIcon, CheckIcon, DotsVerticalIcon, LockClosedIcon, UserIcon, UsersIcon, XIcon, SparklesIcon, } from '@heroicons/react/solid' import clsx from 'clsx' import Textarea from 'react-expanding-textarea' import { OutcomeLabel } from '../outcome-label' import { contractMetrics, Contract, contractPath, tradingAllowed, } from '../../lib/firebase/contracts' import { useUser } from '../../hooks/use-user' import { Linkify } from '../linkify' import { Row } from '../layout/row' import { createComment, MAX_COMMENT_LENGTH } from '../../lib/firebase/comments' import { formatMoney, formatPercent } from '../../../common/util/format' import { Comment } from '../../../common/comment' import { BinaryResolutionOrChance } from '../contract/contract-card' import { SiteLink } from '../site-link' import { Col } from '../layout/col' import { UserLink } from '../user-page' import { DateTimeTooltip } from '../datetime-tooltip' import { Bet } from '../../lib/firebase/bets' import { JoinSpans } from '../join-spans' import { fromNow } from '../../lib/util/time' import BetRow from '../bet-row' import { Avatar } from '../avatar' import { Answer } from '../../../common/answer' import { ActivityItem } from './activity-items' import { FreeResponse, FullContract } from '../../../common/contract' import { BuyButton } from '../yes-no-selector' import { getDpmOutcomeProbability } from '../../../common/calculate-dpm' import { AnswerBetPanel } from '../answers/answer-bet-panel' import { useSaveSeenContract } from '../../hooks/use-seen-contracts' import { User } from '../../../common/user' import { Modal } from '../layout/modal' import { trackClick } from '../../lib/firebase/tracking' import { firebaseLogin } from '../../lib/firebase/users' import { DAY_MS } from '../../../common/util/time' import NewContractBadge from '../new-contract-badge' export function FeedItems(props: { contract: Contract items: ActivityItem[] className?: string betRowClassName?: string }) { const { contract, items, className, betRowClassName } = props const { outcomeType } = contract const ref = useRef(null) useSaveSeenContract(ref, contract) return (
{items.map((item, activityItemIdx) => (
{activityItemIdx !== items.length - 1 || item.type === 'answergroup' ? (
))}
{outcomeType === 'BINARY' && tradingAllowed(contract) && ( )}
) } function FeedItem(props: { item: ActivityItem }) { const { item } = props switch (item.type) { case 'question': return case 'description': return case 'comment': return case 'bet': return case 'betgroup': return case 'answergroup': return case 'answer': return case 'close': return case 'resolve': return case 'commentInput': return } } export function FeedComment(props: { contract: Contract comment: Comment bet: Bet | undefined hideOutcome: boolean truncate: boolean smallAvatar: boolean }) { const { contract, comment, bet, hideOutcome, truncate, smallAvatar } = props let money: string | undefined let outcome: string | undefined let bought: string | undefined if (bet) { outcome = bet.outcome bought = bet.amount >= 0 ? 'bought' : 'sold' money = formatMoney(Math.abs(bet.amount)) } const { text, userUsername, userName, userAvatarUrl, createdTime } = comment return ( <>

{' '} {bought} {money} {!hideOutcome && ( <> {' '} of{' '} )}

) } function RelativeTimestamp(props: { time: number }) { const { time } = props return ( {fromNow(time)} ) } export function CommentInput(props: { contract: Contract commentsByBetId: Record bets: Bet[] }) { // see if we can comment input on any bet: const { contract, bets, commentsByBetId } = props const { outcomeType } = contract const user = useUser() const [comment, setComment] = useState('') let canCommentOnABet = false bets.some((bet) => { // make sure there is not already a comment with a matching bet id: const matchingComment = commentsByBetId[bet.id] if (matchingComment) { return false } const { createdTime, userId } = bet canCommentOnABet = canCommentOnBet(userId, createdTime, user) return canCommentOnABet }) if (canCommentOnABet) return
async function submitComment() { if (!comment) return if (!user) { return await firebaseLogin() } await createComment(contract.id, comment, user) setComment('') } return ( <>