// 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' import { User } from '../../../common/user' export type FeedType = // Main homepage/fold feed, | 'activity' // Comments feed on a market | 'market' // Grouped for a multi-category outcome | 'multi' export function FeedItems(props: { contract: Contract items: ActivityItem[] feedType: FeedType outcome?: string // Which multi-category outcome to filter betRowClassName?: string }) { const { contract, items, feedType, outcome, betRowClassName } = props const { outcomeType } = contract const isBinary = outcomeType === 'BINARY' return (
{items.map((item, activityItemIdx) => (
{activityItemIdx !== items.length - 1 ? (
))}
{isBinary && tradingAllowed(contract) && ( )}
) } function FeedComment(props: { contract: Contract comment: Comment bet: Bet showOutcomeLabel: boolean truncate: boolean }) { const { contract, comment, bet, showOutcomeLabel, truncate } = props const { createdTime } = contract const { amount, outcome } = bet const { text, userUsername, userName, userAvatarUrl } = comment const bought = amount >= 0 ? 'bought' : 'sold' const money = formatMoney(Math.abs(amount)) // const answer = // feedType !== 'multi' && // (contract.answers?.find((answer: Answer) => answer?.id === outcome) as // | Answer // | undefined) return ( <>
{/* {answer && (
{answer.text}
)} */}

{' '} {bought} {money} {showOutcomeLabel && ( <> {' '} of )}

) } function Timestamp(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 && (
{answer.text}
)}
{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