// From https://tailwindui.com/components/application-ui/lists/feeds import { Fragment, useRef, useState } from 'react' import * as _ from 'lodash' import { BanIcon, CheckIcon, DotsVerticalIcon, LockClosedIcon, UserIcon, UsersIcon, XIcon, } 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' export function FeedItems(props: { contract: Contract user: User | null | undefined items: ActivityItem[] className?: string betRowClassName?: string }) { const { contract, user, items, className, betRowClassName } = props const { outcomeType } = contract const ref = useRef(null) useSaveSeenContract(ref, contract, user) 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 'close': return case 'resolve': return } } export function FeedComment(props: { contract: Contract comment: Comment bet: Bet hideOutcome: boolean truncate: boolean smallAvatar: boolean }) { const { contract, comment, bet, hideOutcome, truncate, smallAvatar } = props const { amount, outcome } = bet const { text, userUsername, userName, userAvatarUrl, createdTime } = comment const bought = amount >= 0 ? 'bought' : 'sold' const money = formatMoney(Math.abs(amount)) return ( <>

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

) } function RelativeTimestamp(props: { time: number }) { const { time } = props return ( {fromNow(time)} ) } export function FeedBet(props: { contract: Contract bet: Bet hideOutcome: boolean smallAvatar: boolean bettor?: User // If set: reveal bettor identity }) { const { contract, bet, hideOutcome, smallAvatar, bettor } = props const { id, amount, outcome, createdTime, userId } = bet const user = useUser() const isSelf = user?.id === userId // You can comment if your bet was posted in the last hour const canComment = isSelf && Date.now() - createdTime < 60 * 60 * 1000 const [comment, setComment] = useState('') async function submitComment() { if (!user || !comment || !canComment) return await createComment(contract.id, id, comment, user) } const bought = amount >= 0 ? 'bought' : 'sold' const money = formatMoney(Math.abs(amount)) return ( <>
{isSelf ? ( ) : bettor ? ( ) : (
)}
{isSelf ? 'You' : bettor ? bettor.name : 'A trader'}{' '} {bought} {money} {!hideOutcome && ( <> {' '} of{' '} )} {(canComment || comment) && (