// 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 { createComment } from '../lib/firebase/comments' import { useComments } from '../hooks/use-comments' import { formatMoney } from '../../common/util/format' 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 { useBets } from '../hooks/use-bets' import { Bet } from '../lib/firebase/bets' import { Comment, mapCommentsByBetId } from '../lib/firebase/comments' 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' function FeedComment(props: { activityItem: any moreHref: string feedType: FeedType }) { const { activityItem, moreHref, feedType } = props const { person, text, amount, outcome, createdTime } = activityItem const bought = amount >= 0 ? 'bought' : 'sold' const money = formatMoney(Math.abs(amount)) return ( <>

{' '} {bought} {money}

) } function Timestamp(props: { time: number }) { const { time } = props return ( {fromNow(time)} ) } function FeedBet(props: { activityItem: any; feedType: FeedType }) { const { activityItem, feedType } = props const { id, contractId, amount, outcome, createdTime } = activityItem const user = useUser() const isSelf = user?.id == activityItem.userId // The creator can comment if the 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) return await createComment(contractId, id, comment, user) } const bought = amount >= 0 ? 'bought' : 'sold' const money = formatMoney(Math.abs(amount)) return ( <>
{isSelf ? ( ) : (
)}
{isSelf ? 'You' : 'A trader'} {bought} {money} {canComment && ( // Allow user to comment in an textarea if they are the creator