// From https://tailwindui.com/components/application-ui/lists/feeds import { Fragment, useState } from 'react' import _ from 'lodash' import { BanIcon, CheckIcon, DotsVerticalIcon, LockClosedIcon, UserIcon, UsersIcon, XIcon, } from '@heroicons/react/solid' import dayjs from 'dayjs' import clsx from 'clsx' import Textarea from 'react-expanding-textarea' import { OutcomeLabel } from '../outcome-label' import { contractMetrics, Contract, contractPath, updateContract, tradingAllowed, } from '../../lib/firebase/contracts' import { useUser } from '../../hooks/use-user' import { Linkify } from '../linkify' import { Row } from '../layout/row' import { canAddComment, createComment, MAX_COMMENT_LENGTH, } from '../../lib/firebase/comments' import { formatMoney } from '../../../common/util/format' import { Comment } from '../../../common/comment' import { ResolutionOrChance } from '../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 { parseTags } from '../../../common/util/parse' import { Avatar } from '../avatar' import { useAdmin } from '../../hooks/use-admin' import { Answer } from '../../../common/answer' import { ActivityItem } from './activity-items' export function FeedItems(props: { contract: Contract items: ActivityItem[] betRowClassName?: string }) { const { contract, items, betRowClassName } = props const { outcomeType } = 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 'createanswer': return case 'betgroup': return case 'answergroup': return case 'close': return case 'resolve': return } } function FeedComment(props: { contract: Contract comment: Comment bet: Bet hideOutcome: boolean truncate: boolean }) { const { contract, comment, bet, hideOutcome, truncate } = 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)} ) } function FeedBet(props: { contract: Contract bet: Bet hideOutcome: boolean }) { const { contract, bet, hideOutcome } = props const { id, amount, outcome, createdTime, userId } = bet const user = useUser() const isSelf = user?.id === userId const isCreator = contract.creatorId === userId // You can comment if your bet was posted in the last hour const canComment = canAddComment(createdTime, isSelf) const [comment, setComment] = useState('') async function submitComment() { if (!user || !comment) return await createComment(contract.id, id, comment, user) } const bought = amount >= 0 ? 'bought' : 'sold' const money = formatMoney(Math.abs(amount)) const answer = !hideOutcome && (contract.answers?.find((answer: Answer) => answer?.id === outcome) as | Answer | undefined) return ( <>
{isSelf ? ( ) : isCreator ? ( ) : (
)}
{answer && (
)}
{isSelf ? 'You' : isCreator ? contract.creatorName : 'A trader'} {' '} {bought} {money} {!answer && !hideOutcome && ( <> {' '} of )} {canComment && ( // Allow user to comment in an textarea if they are the creator