2022-01-04 07:21:14 +00:00
|
|
|
// From https://tailwindui.com/components/application-ui/lists/feeds
|
2022-05-11 21:11:46 +00:00
|
|
|
import React, { Fragment, useEffect, useRef, useState } from 'react'
|
2022-03-15 22:27:51 +00:00
|
|
|
import * as _ from 'lodash'
|
2022-05-11 21:11:46 +00:00
|
|
|
import { Dictionary } from 'lodash'
|
2022-01-04 07:21:14 +00:00
|
|
|
import {
|
|
|
|
BanIcon,
|
|
|
|
CheckIcon,
|
2022-01-22 17:46:59 +00:00
|
|
|
DotsVerticalIcon,
|
2022-01-04 07:21:14 +00:00
|
|
|
LockClosedIcon,
|
|
|
|
UserIcon,
|
|
|
|
UsersIcon,
|
|
|
|
XIcon,
|
|
|
|
} from '@heroicons/react/solid'
|
2022-01-27 23:14:18 +00:00
|
|
|
import clsx from 'clsx'
|
2022-02-17 23:00:19 +00:00
|
|
|
import Textarea from 'react-expanding-textarea'
|
2022-01-27 23:14:18 +00:00
|
|
|
|
2022-03-14 20:29:32 +00:00
|
|
|
import { OutcomeLabel } from '../outcome-label'
|
2022-01-11 16:56:26 +00:00
|
|
|
import {
|
|
|
|
Contract,
|
2022-05-11 21:11:46 +00:00
|
|
|
contractMetrics,
|
2022-01-12 19:01:04 +00:00
|
|
|
contractPath,
|
2022-01-26 20:08:03 +00:00
|
|
|
tradingAllowed,
|
2022-05-09 13:04:36 +00:00
|
|
|
} from 'web/lib/firebase/contracts'
|
|
|
|
import { useUser } from 'web/hooks/use-user'
|
2022-03-14 20:29:32 +00:00
|
|
|
import { Linkify } from '../linkify'
|
|
|
|
import { Row } from '../layout/row'
|
2022-05-09 13:04:36 +00:00
|
|
|
import { createComment, MAX_COMMENT_LENGTH } from 'web/lib/firebase/comments'
|
|
|
|
import { formatMoney, formatPercent } from 'common/util/format'
|
|
|
|
import { Comment } from 'common/comment'
|
2022-04-18 23:02:40 +00:00
|
|
|
import { BinaryResolutionOrChance } from '../contract/contract-card'
|
2022-03-14 20:29:32 +00:00
|
|
|
import { SiteLink } from '../site-link'
|
|
|
|
import { Col } from '../layout/col'
|
|
|
|
import { UserLink } from '../user-page'
|
2022-05-09 13:04:36 +00:00
|
|
|
import { Bet } from 'web/lib/firebase/bets'
|
2022-03-14 20:29:32 +00:00
|
|
|
import { JoinSpans } from '../join-spans'
|
2022-03-29 19:56:56 +00:00
|
|
|
import BetRow from '../bet-row'
|
2022-03-14 20:29:32 +00:00
|
|
|
import { Avatar } from '../avatar'
|
2022-05-09 13:04:36 +00:00
|
|
|
import { Answer } from 'common/answer'
|
2022-05-03 20:38:40 +00:00
|
|
|
import { ActivityItem, GENERAL_COMMENTS_OUTCOME_ID } from './activity-items'
|
2022-05-11 21:11:46 +00:00
|
|
|
import { Binary, CPMM, FreeResponse, FullContract } from 'common/contract'
|
2022-03-17 04:42:24 +00:00
|
|
|
import { BuyButton } from '../yes-no-selector'
|
2022-05-09 13:04:36 +00:00
|
|
|
import { getDpmOutcomeProbability } from 'common/calculate-dpm'
|
2022-03-17 04:42:24 +00:00
|
|
|
import { AnswerBetPanel } from '../answers/answer-bet-panel'
|
2022-05-09 13:04:36 +00:00
|
|
|
import { useSaveSeenContract } from 'web/hooks/use-seen-contracts'
|
|
|
|
import { User } from 'common/user'
|
2022-03-29 19:56:56 +00:00
|
|
|
import { Modal } from '../layout/modal'
|
2022-05-09 13:04:36 +00:00
|
|
|
import { trackClick } from 'web/lib/firebase/tracking'
|
|
|
|
import { firebaseLogin } from 'web/lib/firebase/users'
|
|
|
|
import { DAY_MS } from 'common/util/time'
|
2022-04-21 06:03:16 +00:00
|
|
|
import NewContractBadge from '../new-contract-badge'
|
2022-05-05 22:30:30 +00:00
|
|
|
import { RelativeTimestamp } from '../relative-timestamp'
|
2022-05-09 13:04:36 +00:00
|
|
|
import { calculateCpmmSale } from 'common/calculate-cpmm'
|
2022-03-14 20:29:32 +00:00
|
|
|
|
|
|
|
export function FeedItems(props: {
|
|
|
|
contract: Contract
|
|
|
|
items: ActivityItem[]
|
2022-04-06 05:22:43 +00:00
|
|
|
className?: string
|
2022-03-14 20:29:32 +00:00
|
|
|
betRowClassName?: string
|
|
|
|
}) {
|
2022-04-19 05:16:08 +00:00
|
|
|
const { contract, items, className, betRowClassName } = props
|
2022-03-14 20:29:32 +00:00
|
|
|
const { outcomeType } = contract
|
|
|
|
|
2022-03-17 07:29:08 +00:00
|
|
|
const ref = useRef<HTMLDivElement | null>(null)
|
2022-04-19 05:16:08 +00:00
|
|
|
useSaveSeenContract(ref, contract)
|
2022-03-17 07:29:08 +00:00
|
|
|
|
2022-03-14 20:29:32 +00:00
|
|
|
return (
|
2022-05-10 20:59:19 +00:00
|
|
|
<div className={clsx('flow-root', className)} ref={ref}>
|
2022-03-14 20:29:32 +00:00
|
|
|
<div className={clsx(tradingAllowed(contract) ? '' : '-mb-6')}>
|
|
|
|
{items.map((item, activityItemIdx) => (
|
2022-04-26 13:24:57 +00:00
|
|
|
<div
|
|
|
|
key={item.id}
|
|
|
|
className={
|
|
|
|
item.type === 'answer' ? 'relative pb-2' : 'relative pb-6'
|
|
|
|
}
|
|
|
|
>
|
2022-03-14 20:29:32 +00:00
|
|
|
{activityItemIdx !== items.length - 1 ||
|
|
|
|
item.type === 'answergroup' ? (
|
|
|
|
<span
|
|
|
|
className="absolute top-5 left-5 -ml-px h-[calc(100%-2rem)] w-0.5 bg-gray-200"
|
|
|
|
aria-hidden="true"
|
|
|
|
/>
|
|
|
|
) : null}
|
|
|
|
<div className="relative flex items-start space-x-3">
|
|
|
|
<FeedItem item={item} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
{outcomeType === 'BINARY' && tradingAllowed(contract) && (
|
|
|
|
<BetRow contract={contract} className={clsx('mb-2', betRowClassName)} />
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
function FeedItem(props: { item: ActivityItem }) {
|
|
|
|
const { item } = props
|
|
|
|
|
|
|
|
switch (item.type) {
|
|
|
|
case 'question':
|
|
|
|
return <FeedQuestion {...item} />
|
|
|
|
case 'description':
|
|
|
|
return <FeedDescription {...item} />
|
|
|
|
case 'comment':
|
|
|
|
return <FeedComment {...item} />
|
|
|
|
case 'bet':
|
|
|
|
return <FeedBet {...item} />
|
|
|
|
case 'betgroup':
|
|
|
|
return <FeedBetGroup {...item} />
|
|
|
|
case 'answergroup':
|
|
|
|
return <FeedAnswerGroup {...item} />
|
2022-04-26 13:24:57 +00:00
|
|
|
case 'answer':
|
|
|
|
return <FeedAnswerGroup {...item} />
|
2022-03-14 20:29:32 +00:00
|
|
|
case 'close':
|
|
|
|
return <FeedClose {...item} />
|
|
|
|
case 'resolve':
|
|
|
|
return <FeedResolve {...item} />
|
2022-04-21 17:09:06 +00:00
|
|
|
case 'commentInput':
|
|
|
|
return <CommentInput {...item} />
|
2022-05-11 21:11:46 +00:00
|
|
|
case 'commentThread':
|
|
|
|
return <FeedCommentThread {...item} />
|
2022-03-14 20:29:32 +00:00
|
|
|
}
|
2022-03-10 06:29:36 +00:00
|
|
|
}
|
|
|
|
|
2022-05-11 21:11:46 +00:00
|
|
|
export function FeedCommentThread(props: {
|
|
|
|
contract: Contract
|
|
|
|
comments: Comment[]
|
|
|
|
parentComment: Comment
|
|
|
|
betsByUserId: Dictionary<[Bet, ...Bet[]]>
|
|
|
|
truncate?: boolean
|
|
|
|
smallAvatar?: boolean
|
|
|
|
}) {
|
|
|
|
const {
|
|
|
|
contract,
|
|
|
|
comments,
|
|
|
|
betsByUserId,
|
|
|
|
truncate,
|
|
|
|
smallAvatar,
|
|
|
|
parentComment,
|
|
|
|
} = props
|
|
|
|
const [showReply, setShowReply] = useState(false)
|
|
|
|
const [replyToUsername, setReplyToUsername] = useState('')
|
|
|
|
const user = useUser()
|
|
|
|
const commentsList = comments.filter(
|
|
|
|
(comment) => comment.replyToCommentId === parentComment.id
|
|
|
|
)
|
|
|
|
commentsList.unshift(parentComment)
|
|
|
|
const [inputRef, setInputRef] = useState<HTMLTextAreaElement | null>(null)
|
|
|
|
function scrollAndOpenReplyInput(comment: Comment) {
|
|
|
|
setReplyToUsername(comment.userUsername)
|
|
|
|
setShowReply(true)
|
|
|
|
inputRef?.focus()
|
|
|
|
}
|
|
|
|
useEffect(() => {
|
|
|
|
if (showReply && inputRef) inputRef.focus()
|
|
|
|
}, [inputRef, showReply])
|
|
|
|
return (
|
|
|
|
<div className={'w-full flex-col flex-col pr-6'}>
|
|
|
|
{commentsList.map((comment, commentIdx) => (
|
|
|
|
<div
|
|
|
|
key={comment.id}
|
|
|
|
id={comment.id}
|
|
|
|
className={clsx(
|
|
|
|
'flex space-x-3',
|
|
|
|
commentIdx === 0 ? '' : 'mt-4 ml-8'
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
<FeedComment
|
|
|
|
contract={contract}
|
|
|
|
comment={comment}
|
|
|
|
betsBySameUser={betsByUserId[comment.userId] ?? []}
|
|
|
|
onReplyClick={scrollAndOpenReplyInput}
|
|
|
|
smallAvatar={smallAvatar}
|
|
|
|
truncate={truncate}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
{showReply && (
|
2022-05-12 16:27:25 +00:00
|
|
|
<div className={'ml-8 w-full pt-6'}>
|
2022-05-11 21:11:46 +00:00
|
|
|
<CommentInput
|
|
|
|
contract={contract}
|
|
|
|
// Should we allow replies to contain recent bet info?
|
|
|
|
betsByCurrentUser={(user && betsByUserId[user.id]) ?? []}
|
|
|
|
comments={comments}
|
|
|
|
parentComment={parentComment}
|
|
|
|
replyToUsername={replyToUsername}
|
|
|
|
answerOutcome={comments[0].answerOutcome}
|
|
|
|
setRef={setInputRef}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-03-21 01:07:45 +00:00
|
|
|
export function FeedComment(props: {
|
2022-03-14 20:29:32 +00:00
|
|
|
contract: Contract
|
|
|
|
comment: Comment
|
2022-04-29 21:11:04 +00:00
|
|
|
betsBySameUser: Bet[]
|
2022-05-11 21:11:46 +00:00
|
|
|
truncate?: boolean
|
|
|
|
smallAvatar?: boolean
|
|
|
|
onReplyClick?: (comment: Comment) => void
|
2022-01-21 18:53:51 +00:00
|
|
|
}) {
|
2022-04-29 21:11:04 +00:00
|
|
|
const {
|
|
|
|
contract,
|
|
|
|
comment,
|
|
|
|
betsBySameUser,
|
|
|
|
truncate,
|
|
|
|
smallAvatar,
|
2022-05-11 21:11:46 +00:00
|
|
|
onReplyClick,
|
2022-04-29 21:11:04 +00:00
|
|
|
} = props
|
2022-03-14 20:29:32 +00:00
|
|
|
const { text, userUsername, userName, userAvatarUrl, createdTime } = comment
|
2022-04-29 21:11:04 +00:00
|
|
|
let outcome: string | undefined,
|
|
|
|
bought: string | undefined,
|
|
|
|
money: string | undefined
|
|
|
|
|
|
|
|
const matchedBet = betsBySameUser.find((bet) => bet.id === comment.betId)
|
|
|
|
if (matchedBet) {
|
|
|
|
outcome = matchedBet.outcome
|
|
|
|
bought = matchedBet.amount >= 0 ? 'bought' : 'sold'
|
|
|
|
money = formatMoney(Math.abs(matchedBet.amount))
|
|
|
|
}
|
|
|
|
|
|
|
|
// Only calculated if they don't have a matching bet
|
|
|
|
const { userPosition, userPositionMoney, yesFloorShares, noFloorShares } =
|
|
|
|
getBettorsPosition(
|
|
|
|
contract,
|
|
|
|
comment.createdTime,
|
|
|
|
matchedBet ? [] : betsBySameUser
|
|
|
|
)
|
2022-01-18 03:36:33 +00:00
|
|
|
|
2022-01-04 07:21:14 +00:00
|
|
|
return (
|
|
|
|
<>
|
2022-03-14 21:56:53 +00:00
|
|
|
<Avatar
|
|
|
|
className={clsx(smallAvatar && 'ml-1')}
|
|
|
|
size={smallAvatar ? 'sm' : undefined}
|
|
|
|
username={userUsername}
|
|
|
|
avatarUrl={userAvatarUrl}
|
|
|
|
/>
|
2022-01-04 07:21:14 +00:00
|
|
|
<div className="min-w-0 flex-1">
|
2022-05-09 22:50:20 +00:00
|
|
|
<p className="mt-0.5 text-sm text-gray-500">
|
|
|
|
<UserLink
|
|
|
|
className="text-gray-500"
|
|
|
|
username={userUsername}
|
|
|
|
name={userName}
|
|
|
|
/>{' '}
|
|
|
|
{!matchedBet && userPosition > 0 && (
|
|
|
|
<>
|
|
|
|
{'had ' + userPositionMoney + ' '}
|
2022-03-14 20:29:32 +00:00
|
|
|
<>
|
2022-05-09 22:50:20 +00:00
|
|
|
{' of '}
|
|
|
|
<OutcomeLabel
|
|
|
|
outcome={yesFloorShares > noFloorShares ? 'YES' : 'NO'}
|
|
|
|
contract={contract}
|
|
|
|
truncate="short"
|
|
|
|
/>
|
2022-03-14 20:29:32 +00:00
|
|
|
</>
|
2022-04-29 21:11:04 +00:00
|
|
|
</>
|
2022-05-09 22:50:20 +00:00
|
|
|
)}
|
|
|
|
<>
|
|
|
|
{bought} {money}
|
2022-05-11 21:11:46 +00:00
|
|
|
{contract.outcomeType !== 'FREE_RESPONSE' && outcome && (
|
2022-05-09 22:50:20 +00:00
|
|
|
<>
|
|
|
|
{' '}
|
|
|
|
of{' '}
|
|
|
|
<OutcomeLabel
|
|
|
|
outcome={outcome ? outcome : ''}
|
|
|
|
contract={contract}
|
|
|
|
truncate="short"
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</>
|
|
|
|
<RelativeTimestamp time={createdTime} />
|
|
|
|
</p>
|
2022-01-21 18:53:51 +00:00
|
|
|
<TruncatedComment
|
|
|
|
comment={text}
|
2022-03-14 20:29:32 +00:00
|
|
|
moreHref={contractPath(contract)}
|
|
|
|
shouldTruncate={truncate}
|
2022-01-21 18:53:51 +00:00
|
|
|
/>
|
2022-05-11 21:11:46 +00:00
|
|
|
{onReplyClick && (
|
|
|
|
<button
|
2022-05-12 16:27:25 +00:00
|
|
|
className={'text-xs font-bold text-gray-500 hover:underline'}
|
2022-05-11 21:11:46 +00:00
|
|
|
onClick={() => onReplyClick(comment)}
|
|
|
|
>
|
|
|
|
Reply
|
|
|
|
</button>
|
|
|
|
)}
|
2022-01-04 07:21:14 +00:00
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-04-29 21:11:04 +00:00
|
|
|
export function CommentInput(props: {
|
|
|
|
contract: Contract
|
|
|
|
betsByCurrentUser: Bet[]
|
|
|
|
comments: Comment[]
|
2022-05-11 21:11:46 +00:00
|
|
|
// Tie a comment to an free response answer outcome
|
2022-05-03 20:38:40 +00:00
|
|
|
answerOutcome?: string
|
2022-05-11 21:11:46 +00:00
|
|
|
// Tie a comment to another comment
|
|
|
|
parentComment?: Comment
|
|
|
|
replyToUsername?: string
|
2022-05-12 14:59:05 +00:00
|
|
|
setRef?: (ref: HTMLTextAreaElement) => void
|
2022-04-29 21:11:04 +00:00
|
|
|
}) {
|
2022-05-11 21:11:46 +00:00
|
|
|
const {
|
|
|
|
contract,
|
|
|
|
betsByCurrentUser,
|
|
|
|
comments,
|
|
|
|
answerOutcome,
|
|
|
|
parentComment,
|
|
|
|
replyToUsername,
|
|
|
|
setRef,
|
|
|
|
} = props
|
2022-04-21 17:09:06 +00:00
|
|
|
const user = useUser()
|
|
|
|
const [comment, setComment] = useState('')
|
2022-05-03 20:38:40 +00:00
|
|
|
const [focused, setFocused] = useState(false)
|
2022-04-21 17:09:06 +00:00
|
|
|
|
2022-05-11 21:11:46 +00:00
|
|
|
const mostRecentCommentableBet = getMostRecentCommentableBet(
|
|
|
|
betsByCurrentUser,
|
|
|
|
comments,
|
|
|
|
user,
|
|
|
|
answerOutcome
|
|
|
|
)
|
2022-05-03 13:51:25 +00:00
|
|
|
const { id } = mostRecentCommentableBet || { id: undefined }
|
|
|
|
|
2022-05-11 21:11:46 +00:00
|
|
|
useEffect(() => {
|
|
|
|
if (!replyToUsername || !user || replyToUsername === user.username) return
|
|
|
|
const replacement = `@${replyToUsername} `
|
|
|
|
setComment(replacement + comment.replace(replacement, ''))
|
|
|
|
}, [user, replyToUsername])
|
|
|
|
|
2022-05-03 20:38:40 +00:00
|
|
|
async function submitComment(betId: string | undefined) {
|
2022-05-03 13:51:25 +00:00
|
|
|
if (!user) {
|
|
|
|
return await firebaseLogin()
|
|
|
|
}
|
2022-05-03 20:38:40 +00:00
|
|
|
if (!comment) return
|
2022-05-11 21:11:46 +00:00
|
|
|
|
|
|
|
// Update state asap to avoid double submission.
|
|
|
|
const commentValue = comment.toString()
|
2022-05-03 13:51:25 +00:00
|
|
|
setComment('')
|
2022-05-11 21:11:46 +00:00
|
|
|
await createComment(
|
|
|
|
contract.id,
|
|
|
|
commentValue,
|
|
|
|
user,
|
|
|
|
betId,
|
|
|
|
answerOutcome,
|
|
|
|
parentComment?.id
|
|
|
|
)
|
2022-04-29 21:11:04 +00:00
|
|
|
}
|
2022-05-03 13:51:25 +00:00
|
|
|
|
2022-04-29 21:11:04 +00:00
|
|
|
const { userPosition, userPositionMoney, yesFloorShares, noFloorShares } =
|
|
|
|
getBettorsPosition(contract, Date.now(), betsByCurrentUser)
|
|
|
|
|
2022-05-11 21:11:46 +00:00
|
|
|
const shouldCollapseAfterClickOutside = false
|
|
|
|
|
2022-04-21 17:09:06 +00:00
|
|
|
return (
|
|
|
|
<>
|
2022-05-11 21:11:46 +00:00
|
|
|
<Row className={'mb-2 flex w-full gap-2'}>
|
|
|
|
<div className={'mt-1'}>
|
|
|
|
<Avatar avatarUrl={user?.avatarUrl} username={user?.username} />
|
|
|
|
</div>
|
2022-05-03 20:38:40 +00:00
|
|
|
<div className={'min-w-0 flex-1'}>
|
2022-04-26 13:24:57 +00:00
|
|
|
<div className="text-sm text-gray-500">
|
2022-05-11 21:11:46 +00:00
|
|
|
<div className={'mb-1'}>
|
|
|
|
{mostRecentCommentableBet && (
|
|
|
|
<BetStatusText
|
|
|
|
contract={contract}
|
|
|
|
bet={mostRecentCommentableBet}
|
|
|
|
isSelf={true}
|
2022-05-12 14:59:05 +00:00
|
|
|
hideOutcome={contract.outcomeType === 'FREE_RESPONSE'}
|
2022-05-11 21:11:46 +00:00
|
|
|
/>
|
|
|
|
)}
|
|
|
|
{!mostRecentCommentableBet && user && userPosition > 0 && (
|
2022-04-29 21:11:04 +00:00
|
|
|
<>
|
2022-05-11 21:11:46 +00:00
|
|
|
{'You have ' + userPositionMoney + ' '}
|
|
|
|
<>
|
|
|
|
{' of '}
|
|
|
|
<OutcomeLabel
|
|
|
|
outcome={yesFloorShares > noFloorShares ? 'YES' : 'NO'}
|
|
|
|
contract={contract}
|
|
|
|
truncate="short"
|
|
|
|
/>
|
|
|
|
</>
|
2022-04-29 21:11:04 +00:00
|
|
|
</>
|
2022-05-11 21:11:46 +00:00
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<Row className="gap-1.5">
|
|
|
|
<Textarea
|
2022-05-12 14:59:05 +00:00
|
|
|
ref={(ref: HTMLTextAreaElement) => setRef?.(ref)}
|
2022-05-11 21:11:46 +00:00
|
|
|
value={comment}
|
|
|
|
onChange={(e) => setComment(e.target.value)}
|
|
|
|
className="textarea textarea-bordered w-full resize-none"
|
|
|
|
placeholder={
|
|
|
|
parentComment || answerOutcome
|
|
|
|
? 'Write a reply... '
|
|
|
|
: 'Write a comment...'
|
|
|
|
}
|
|
|
|
autoFocus={focused}
|
|
|
|
rows={focused ? 3 : 1}
|
|
|
|
onFocus={() => setFocused(true)}
|
|
|
|
onBlur={() =>
|
|
|
|
shouldCollapseAfterClickOutside && setFocused(false)
|
|
|
|
}
|
|
|
|
maxLength={MAX_COMMENT_LENGTH}
|
|
|
|
onKeyDown={(e) => {
|
2022-05-12 14:59:05 +00:00
|
|
|
if (e.key === 'Enter' && (e.ctrlKey || e.metaKey)) {
|
2022-05-11 21:11:46 +00:00
|
|
|
e.preventDefault()
|
|
|
|
submitComment(id)
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<div
|
|
|
|
className={clsx(
|
|
|
|
'flex justify-center',
|
|
|
|
focused ? 'items-end' : 'items-center'
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{!user && (
|
|
|
|
<button
|
|
|
|
className={
|
|
|
|
'btn btn-outline btn-sm text-transform: capitalize'
|
2022-05-03 20:38:40 +00:00
|
|
|
}
|
2022-05-11 21:11:46 +00:00
|
|
|
onClick={() => submitComment(id)}
|
|
|
|
>
|
|
|
|
Sign in to Comment
|
|
|
|
</button>
|
|
|
|
)}
|
|
|
|
{user && (
|
|
|
|
<button
|
|
|
|
className={clsx(
|
2022-05-12 14:59:05 +00:00
|
|
|
'btn text-transform: block capitalize',
|
2022-05-11 21:11:46 +00:00
|
|
|
focused && comment
|
|
|
|
? 'btn-outline btn-sm '
|
|
|
|
: 'btn-ghost btn-sm text-gray-500'
|
|
|
|
)}
|
|
|
|
onClick={() => {
|
|
|
|
if (!focused) return
|
|
|
|
else {
|
|
|
|
submitComment(id)
|
|
|
|
setFocused(false)
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{parentComment || answerOutcome ? 'Reply' : 'Comment'}
|
|
|
|
</button>
|
|
|
|
)}
|
2022-05-03 20:38:40 +00:00
|
|
|
</div>
|
2022-05-11 21:11:46 +00:00
|
|
|
</Row>
|
2022-04-21 17:09:06 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2022-04-26 13:24:57 +00:00
|
|
|
</Row>
|
2022-04-21 17:09:06 +00:00
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-04-29 21:11:04 +00:00
|
|
|
function getBettorsPosition(
|
|
|
|
contract: Contract,
|
|
|
|
createdTime: number,
|
|
|
|
bets: Bet[]
|
|
|
|
) {
|
|
|
|
let yesFloorShares = 0,
|
|
|
|
yesShares = 0,
|
|
|
|
noShares = 0,
|
|
|
|
noFloorShares = 0
|
|
|
|
|
|
|
|
const emptyReturn = {
|
|
|
|
userPosition: 0,
|
|
|
|
userPositionMoney: 0,
|
|
|
|
yesFloorShares,
|
|
|
|
noFloorShares,
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: show which of the answers was their majority stake at time of comment for FR?
|
|
|
|
if (contract.outcomeType != 'BINARY') {
|
|
|
|
return emptyReturn
|
|
|
|
}
|
|
|
|
if (bets.length === 0) {
|
|
|
|
return emptyReturn
|
|
|
|
}
|
|
|
|
|
|
|
|
// Calculate the majority shares they had when they made the comment
|
|
|
|
const betsBefore = bets.filter((prevBet) => prevBet.createdTime < createdTime)
|
|
|
|
const [yesBets, noBets] = _.partition(
|
|
|
|
betsBefore ?? [],
|
|
|
|
(bet) => bet.outcome === 'YES'
|
|
|
|
)
|
|
|
|
yesShares = _.sumBy(yesBets, (bet) => bet.shares)
|
|
|
|
noShares = _.sumBy(noBets, (bet) => bet.shares)
|
|
|
|
yesFloorShares = Math.floor(yesShares)
|
|
|
|
noFloorShares = Math.floor(noShares)
|
|
|
|
|
|
|
|
const userPosition = yesFloorShares || noFloorShares
|
|
|
|
const { saleValue } = calculateCpmmSale(
|
|
|
|
contract as FullContract<CPMM, Binary>,
|
|
|
|
yesShares || noShares,
|
|
|
|
yesFloorShares > noFloorShares ? 'YES' : 'NO'
|
|
|
|
)
|
|
|
|
const userPositionMoney = formatMoney(Math.abs(saleValue))
|
|
|
|
return { userPosition, userPositionMoney, yesFloorShares, noFloorShares }
|
|
|
|
}
|
|
|
|
|
2022-03-21 01:07:45 +00:00
|
|
|
export function FeedBet(props: {
|
2022-03-14 20:29:32 +00:00
|
|
|
contract: Contract
|
|
|
|
bet: Bet
|
|
|
|
hideOutcome: boolean
|
2022-03-14 21:56:53 +00:00
|
|
|
smallAvatar: boolean
|
2022-03-21 01:07:45 +00:00
|
|
|
bettor?: User // If set: reveal bettor identity
|
2022-03-14 20:29:32 +00:00
|
|
|
}) {
|
2022-05-03 13:51:25 +00:00
|
|
|
const { contract, bet, hideOutcome, smallAvatar, bettor } = props
|
|
|
|
const { userId } = bet
|
2022-01-04 07:21:14 +00:00
|
|
|
const user = useUser()
|
2022-03-14 20:29:32 +00:00
|
|
|
const isSelf = user?.id === userId
|
2022-01-18 03:36:33 +00:00
|
|
|
|
2022-01-04 07:21:14 +00:00
|
|
|
return (
|
|
|
|
<>
|
2022-04-29 21:11:04 +00:00
|
|
|
<Row className={'flex w-full gap-2 pt-3'}>
|
2022-05-09 21:32:59 +00:00
|
|
|
{isSelf ? (
|
|
|
|
<Avatar
|
|
|
|
className={clsx(smallAvatar && 'ml-1')}
|
|
|
|
size={smallAvatar ? 'sm' : undefined}
|
|
|
|
avatarUrl={user.avatarUrl}
|
|
|
|
username={user.username}
|
|
|
|
/>
|
|
|
|
) : bettor ? (
|
|
|
|
<Avatar
|
|
|
|
className={clsx(smallAvatar && 'ml-1')}
|
|
|
|
size={smallAvatar ? 'sm' : undefined}
|
|
|
|
avatarUrl={bettor.avatarUrl}
|
|
|
|
username={bettor.username}
|
|
|
|
/>
|
|
|
|
) : (
|
|
|
|
<div className="relative px-1">
|
|
|
|
<div className="flex h-8 w-8 items-center justify-center rounded-full bg-gray-200">
|
|
|
|
<UserIcon className="h-5 w-5 text-gray-500" aria-hidden="true" />
|
2022-03-10 06:29:36 +00:00
|
|
|
</div>
|
2022-05-09 21:32:59 +00:00
|
|
|
</div>
|
|
|
|
)}
|
2022-04-29 21:11:04 +00:00
|
|
|
<div className={'min-w-0 flex-1 py-1.5'}>
|
2022-05-03 13:51:25 +00:00
|
|
|
<BetStatusText
|
|
|
|
bet={bet}
|
|
|
|
contract={contract}
|
|
|
|
isSelf={isSelf}
|
|
|
|
bettor={bettor}
|
2022-05-12 14:59:05 +00:00
|
|
|
hideOutcome={hideOutcome}
|
2022-05-03 13:51:25 +00:00
|
|
|
/>
|
2022-04-29 21:11:04 +00:00
|
|
|
</div>
|
|
|
|
</Row>
|
2022-01-04 07:21:14 +00:00
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-05-03 13:51:25 +00:00
|
|
|
function BetStatusText(props: {
|
|
|
|
contract: Contract
|
|
|
|
bet: Bet
|
|
|
|
isSelf: boolean
|
|
|
|
bettor?: User
|
2022-05-12 14:59:05 +00:00
|
|
|
hideOutcome?: boolean
|
2022-05-03 13:51:25 +00:00
|
|
|
}) {
|
2022-05-12 14:59:05 +00:00
|
|
|
const { bet, contract, bettor, isSelf, hideOutcome } = props
|
2022-05-03 13:51:25 +00:00
|
|
|
const { amount, outcome, createdTime } = bet
|
|
|
|
|
|
|
|
const bought = amount >= 0 ? 'bought' : 'sold'
|
|
|
|
const money = formatMoney(Math.abs(amount))
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className="text-sm text-gray-500">
|
|
|
|
<span>{isSelf ? 'You' : bettor ? bettor.name : 'A trader'}</span> {bought}{' '}
|
|
|
|
{money}
|
2022-05-12 14:59:05 +00:00
|
|
|
{!hideOutcome && (
|
2022-05-03 13:51:25 +00:00
|
|
|
<>
|
|
|
|
{' '}
|
|
|
|
of{' '}
|
|
|
|
<OutcomeLabel
|
|
|
|
outcome={outcome}
|
|
|
|
contract={contract}
|
|
|
|
truncate="short"
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
)}
|
|
|
|
<RelativeTimestamp time={createdTime} />
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-01-21 18:53:51 +00:00
|
|
|
function TruncatedComment(props: {
|
|
|
|
comment: string
|
|
|
|
moreHref: string
|
|
|
|
shouldTruncate?: boolean
|
|
|
|
}) {
|
|
|
|
const { comment, moreHref, shouldTruncate } = props
|
|
|
|
let truncated = comment
|
|
|
|
|
|
|
|
// Keep descriptions to at most 400 characters
|
2022-01-22 17:46:59 +00:00
|
|
|
const MAX_CHARS = 400
|
|
|
|
if (shouldTruncate && truncated.length > MAX_CHARS) {
|
|
|
|
truncated = truncated.slice(0, MAX_CHARS)
|
2022-01-21 18:53:51 +00:00
|
|
|
// Make sure to end on a space
|
|
|
|
const i = truncated.lastIndexOf(' ')
|
|
|
|
truncated = truncated.slice(0, i)
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2022-03-05 00:06:11 +00:00
|
|
|
<div
|
|
|
|
className="mt-2 whitespace-pre-line break-words text-gray-700"
|
|
|
|
style={{ fontSize: 15 }}
|
|
|
|
>
|
2022-01-21 18:53:51 +00:00
|
|
|
<Linkify text={truncated} />
|
|
|
|
{truncated != comment && (
|
|
|
|
<SiteLink href={moreHref} className="text-indigo-700">
|
|
|
|
... (show more)
|
|
|
|
</SiteLink>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-03-14 20:29:32 +00:00
|
|
|
export function FeedQuestion(props: {
|
2022-03-05 00:06:11 +00:00
|
|
|
contract: Contract
|
2022-04-11 21:13:26 +00:00
|
|
|
showDescription: boolean
|
|
|
|
contractPath?: string
|
2022-03-05 00:06:11 +00:00
|
|
|
}) {
|
|
|
|
const { contract, showDescription } = props
|
2022-04-20 22:25:29 +00:00
|
|
|
const {
|
|
|
|
creatorName,
|
|
|
|
creatorUsername,
|
|
|
|
question,
|
|
|
|
outcomeType,
|
|
|
|
volume,
|
|
|
|
createdTime,
|
|
|
|
} = contract
|
2022-03-23 05:02:47 +00:00
|
|
|
const { volumeLabel } = contractMetrics(contract)
|
2022-02-17 23:00:19 +00:00
|
|
|
const isBinary = outcomeType === 'BINARY'
|
2022-04-20 22:25:29 +00:00
|
|
|
const isNew = createdTime > Date.now() - DAY_MS
|
2022-01-11 16:56:26 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2022-02-04 18:30:56 +00:00
|
|
|
<Avatar
|
|
|
|
username={contract.creatorUsername}
|
|
|
|
avatarUrl={contract.creatorAvatarUrl}
|
|
|
|
/>
|
2022-01-11 16:56:26 +00:00
|
|
|
<div className="min-w-0 flex-1 py-1.5">
|
2022-02-11 18:40:22 +00:00
|
|
|
<div className="mb-2 text-sm text-gray-500">
|
2022-01-13 21:16:47 +00:00
|
|
|
<UserLink
|
|
|
|
className="text-gray-900"
|
|
|
|
name={creatorName}
|
|
|
|
username={creatorUsername}
|
|
|
|
/>{' '}
|
2022-01-22 00:10:38 +00:00
|
|
|
asked
|
2022-02-24 04:20:42 +00:00
|
|
|
{/* Currently hidden on mobile; ideally we'd fit this in somewhere. */}
|
2022-04-21 06:03:16 +00:00
|
|
|
<div className="relative -top-2 float-right ">
|
2022-04-20 22:25:29 +00:00
|
|
|
{isNew || volume === 0 ? (
|
2022-04-21 06:03:16 +00:00
|
|
|
<NewContractBadge />
|
2022-04-20 22:25:29 +00:00
|
|
|
) : (
|
2022-04-21 06:03:16 +00:00
|
|
|
<span className="hidden text-gray-400 sm:inline">
|
2022-04-20 22:25:29 +00:00
|
|
|
{volumeLabel}
|
|
|
|
</span>
|
|
|
|
)}
|
|
|
|
</div>
|
2022-01-11 16:56:26 +00:00
|
|
|
</div>
|
2022-03-05 00:06:11 +00:00
|
|
|
<Col className="items-start justify-between gap-2 sm:flex-row sm:gap-4">
|
2022-05-09 22:50:20 +00:00
|
|
|
<SiteLink
|
|
|
|
href={
|
|
|
|
props.contractPath ? props.contractPath : contractPath(contract)
|
|
|
|
}
|
|
|
|
onClick={() => trackClick(contract.id)}
|
|
|
|
className="text-lg text-indigo-700 sm:text-xl"
|
|
|
|
>
|
|
|
|
{question}
|
|
|
|
</SiteLink>
|
2022-04-18 23:02:40 +00:00
|
|
|
{isBinary && (
|
|
|
|
<BinaryResolutionOrChance
|
|
|
|
className="items-center"
|
|
|
|
contract={contract}
|
|
|
|
/>
|
2022-02-17 23:00:19 +00:00
|
|
|
)}
|
2022-01-11 20:57:44 +00:00
|
|
|
</Col>
|
2022-03-05 00:06:11 +00:00
|
|
|
{showDescription && (
|
|
|
|
<TruncatedComment
|
|
|
|
comment={contract.description}
|
|
|
|
moreHref={contractPath(contract)}
|
|
|
|
shouldTruncate
|
|
|
|
/>
|
|
|
|
)}
|
2022-01-11 16:56:26 +00:00
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-05-11 21:11:46 +00:00
|
|
|
function getMostRecentCommentableBet(
|
|
|
|
betsByCurrentUser: Bet[],
|
|
|
|
comments: Comment[],
|
|
|
|
user?: User | null,
|
|
|
|
answerOutcome?: string
|
|
|
|
) {
|
|
|
|
return betsByCurrentUser
|
|
|
|
.filter((bet) => {
|
|
|
|
if (
|
|
|
|
canCommentOnBet(bet, user) &&
|
|
|
|
// The bet doesn't already have a comment
|
|
|
|
!comments.some((comment) => comment.betId == bet.id)
|
|
|
|
) {
|
|
|
|
if (!answerOutcome) return true
|
|
|
|
// If we're in free response, don't allow commenting on ante bet
|
|
|
|
return (
|
|
|
|
bet.outcome !== GENERAL_COMMENTS_OUTCOME_ID &&
|
|
|
|
answerOutcome === bet.outcome
|
|
|
|
)
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
})
|
|
|
|
.sort((b1, b2) => b1.createdTime - b2.createdTime)
|
|
|
|
.pop()
|
|
|
|
}
|
|
|
|
|
2022-05-03 20:38:40 +00:00
|
|
|
function canCommentOnBet(bet: Bet, user?: User | null) {
|
|
|
|
const { userId, createdTime, isRedemption } = bet
|
|
|
|
const isSelf = user?.id === userId
|
2022-04-21 17:09:06 +00:00
|
|
|
// You can comment if your bet was posted in the last hour
|
2022-05-03 20:38:40 +00:00
|
|
|
return !isRedemption && isSelf && Date.now() - createdTime < 60 * 60 * 1000
|
2022-04-21 17:09:06 +00:00
|
|
|
}
|
|
|
|
|
2022-01-11 16:56:26 +00:00
|
|
|
function FeedDescription(props: { contract: Contract }) {
|
2022-01-04 07:21:14 +00:00
|
|
|
const { contract } = props
|
2022-01-13 21:16:47 +00:00
|
|
|
const { creatorName, creatorUsername } = contract
|
2022-01-04 07:21:14 +00:00
|
|
|
const user = useUser()
|
|
|
|
const isCreator = user?.id === contract.creatorId
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2022-02-04 18:30:56 +00:00
|
|
|
<Avatar
|
|
|
|
username={contract.creatorUsername}
|
|
|
|
avatarUrl={contract.creatorAvatarUrl}
|
|
|
|
/>
|
2022-01-04 07:21:14 +00:00
|
|
|
<div className="min-w-0 flex-1 py-1.5">
|
|
|
|
<div className="text-sm text-gray-500">
|
2022-01-13 21:16:47 +00:00
|
|
|
<UserLink
|
|
|
|
className="text-gray-900"
|
|
|
|
name={creatorName}
|
|
|
|
username={creatorUsername}
|
|
|
|
/>{' '}
|
2022-03-14 20:29:32 +00:00
|
|
|
created this market <RelativeTimestamp time={contract.createdTime} />
|
2022-01-04 07:21:14 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-02-17 23:00:19 +00:00
|
|
|
function OutcomeIcon(props: { outcome?: string }) {
|
2022-01-04 07:21:14 +00:00
|
|
|
const { outcome } = props
|
|
|
|
switch (outcome) {
|
|
|
|
case 'YES':
|
|
|
|
return <CheckIcon className="h-5 w-5 text-gray-500" aria-hidden="true" />
|
|
|
|
case 'NO':
|
|
|
|
return <XIcon className="h-5 w-5 text-gray-500" aria-hidden="true" />
|
|
|
|
case 'CANCEL':
|
|
|
|
return <BanIcon className="h-5 w-5 text-gray-500" aria-hidden="true" />
|
2022-02-17 23:00:19 +00:00
|
|
|
default:
|
|
|
|
return <CheckIcon className="h-5 w-5 text-gray-500" aria-hidden="true" />
|
2022-01-04 07:21:14 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function FeedResolve(props: { contract: Contract }) {
|
|
|
|
const { contract } = props
|
2022-01-13 21:16:47 +00:00
|
|
|
const { creatorName, creatorUsername } = contract
|
2022-01-04 07:21:14 +00:00
|
|
|
const resolution = contract.resolution || 'CANCEL'
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div>
|
|
|
|
<div className="relative px-1">
|
2022-02-11 18:40:22 +00:00
|
|
|
<div className="flex h-8 w-8 items-center justify-center rounded-full bg-gray-200">
|
2022-01-04 07:21:14 +00:00
|
|
|
<OutcomeIcon outcome={resolution} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="min-w-0 flex-1 py-1.5">
|
|
|
|
<div className="text-sm text-gray-500">
|
2022-01-13 21:16:47 +00:00
|
|
|
<UserLink
|
|
|
|
className="text-gray-900"
|
|
|
|
name={creatorName}
|
|
|
|
username={creatorUsername}
|
|
|
|
/>{' '}
|
2022-04-18 23:02:40 +00:00
|
|
|
resolved this market to{' '}
|
|
|
|
<OutcomeLabel
|
|
|
|
outcome={resolution}
|
|
|
|
contract={contract}
|
|
|
|
truncate="long"
|
|
|
|
/>{' '}
|
2022-03-14 20:29:32 +00:00
|
|
|
<RelativeTimestamp time={contract.resolutionTime || 0} />
|
2022-01-04 07:21:14 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
function FeedClose(props: { contract: Contract }) {
|
|
|
|
const { contract } = props
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div>
|
|
|
|
<div className="relative px-1">
|
2022-02-11 18:40:22 +00:00
|
|
|
<div className="flex h-8 w-8 items-center justify-center rounded-full bg-gray-200">
|
2022-01-04 07:21:14 +00:00
|
|
|
<LockClosedIcon
|
|
|
|
className="h-5 w-5 text-gray-500"
|
|
|
|
aria-hidden="true"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="min-w-0 flex-1 py-1.5">
|
|
|
|
<div className="text-sm text-gray-500">
|
|
|
|
Trading closed in this market{' '}
|
2022-03-14 20:29:32 +00:00
|
|
|
<RelativeTimestamp time={contract.closeTime || 0} />
|
2022-01-04 07:21:14 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-04-18 23:02:40 +00:00
|
|
|
function BetGroupSpan(props: {
|
|
|
|
contract: Contract
|
|
|
|
bets: Bet[]
|
|
|
|
outcome?: string
|
|
|
|
}) {
|
|
|
|
const { contract, bets, outcome } = props
|
2022-01-18 03:36:33 +00:00
|
|
|
|
|
|
|
const numberTraders = _.uniqBy(bets, (b) => b.userId).length
|
|
|
|
|
|
|
|
const [buys, sells] = _.partition(bets, (bet) => bet.amount >= 0)
|
|
|
|
const buyTotal = _.sumBy(buys, (b) => b.amount)
|
|
|
|
const sellTotal = _.sumBy(sells, (b) => -b.amount)
|
|
|
|
|
|
|
|
return (
|
|
|
|
<span>
|
|
|
|
{numberTraders} {numberTraders > 1 ? 'traders' : 'trader'}{' '}
|
|
|
|
<JoinSpans>
|
|
|
|
{buyTotal > 0 && <>bought {formatMoney(buyTotal)} </>}
|
|
|
|
{sellTotal > 0 && <>sold {formatMoney(sellTotal)} </>}
|
|
|
|
</JoinSpans>
|
2022-03-14 20:29:32 +00:00
|
|
|
{outcome && (
|
|
|
|
<>
|
|
|
|
{' '}
|
2022-04-18 23:02:40 +00:00
|
|
|
of{' '}
|
|
|
|
<OutcomeLabel
|
|
|
|
outcome={outcome}
|
|
|
|
contract={contract}
|
|
|
|
truncate="short"
|
|
|
|
/>
|
2022-03-14 20:29:32 +00:00
|
|
|
</>
|
|
|
|
)}{' '}
|
2022-01-18 03:36:33 +00:00
|
|
|
</span>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-03-14 20:29:32 +00:00
|
|
|
function FeedBetGroup(props: {
|
|
|
|
contract: Contract
|
|
|
|
bets: Bet[]
|
|
|
|
hideOutcome: boolean
|
|
|
|
}) {
|
2022-04-18 23:02:40 +00:00
|
|
|
const { contract, bets, hideOutcome } = props
|
2022-01-04 07:21:14 +00:00
|
|
|
|
2022-02-17 23:00:19 +00:00
|
|
|
const betGroups = _.groupBy(bets, (bet) => bet.outcome)
|
|
|
|
const outcomes = Object.keys(betGroups)
|
2022-01-18 03:36:33 +00:00
|
|
|
|
2022-02-03 08:56:49 +00:00
|
|
|
// Use the time of the last bet for the entire group
|
|
|
|
const createdTime = bets[bets.length - 1].createdTime
|
2022-01-04 07:21:14 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<div>
|
|
|
|
<div className="relative px-1">
|
2022-02-11 18:40:22 +00:00
|
|
|
<div className="flex h-8 w-8 items-center justify-center rounded-full bg-gray-200">
|
2022-01-19 07:54:00 +00:00
|
|
|
<UsersIcon className="h-5 w-5 text-gray-500" aria-hidden="true" />
|
2022-01-04 07:21:14 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2022-03-14 22:11:10 +00:00
|
|
|
<div className={clsx('min-w-0 flex-1', outcomes.length === 1 && 'mt-1')}>
|
2022-01-04 07:21:14 +00:00
|
|
|
<div className="text-sm text-gray-500">
|
2022-02-17 23:00:19 +00:00
|
|
|
{outcomes.map((outcome, index) => (
|
|
|
|
<Fragment key={outcome}>
|
2022-02-24 19:26:01 +00:00
|
|
|
<BetGroupSpan
|
2022-04-18 23:02:40 +00:00
|
|
|
contract={contract}
|
2022-03-14 20:29:32 +00:00
|
|
|
outcome={hideOutcome ? undefined : outcome}
|
2022-02-24 19:26:01 +00:00
|
|
|
bets={betGroups[outcome]}
|
|
|
|
/>
|
2022-02-17 23:00:19 +00:00
|
|
|
{index !== outcomes.length - 1 && <br />}
|
|
|
|
</Fragment>
|
|
|
|
))}
|
2022-03-14 20:29:32 +00:00
|
|
|
<RelativeTimestamp time={createdTime} />
|
2022-01-04 07:21:14 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-03-14 20:29:32 +00:00
|
|
|
function FeedAnswerGroup(props: {
|
2022-03-15 22:27:51 +00:00
|
|
|
contract: FullContract<any, FreeResponse>
|
2022-03-14 20:29:32 +00:00
|
|
|
answer: Answer
|
|
|
|
items: ActivityItem[]
|
2022-04-26 13:24:57 +00:00
|
|
|
type: string
|
2022-05-11 21:11:46 +00:00
|
|
|
betsByCurrentUser?: Bet[]
|
|
|
|
comments?: Comment[]
|
2022-03-14 20:29:32 +00:00
|
|
|
}) {
|
2022-05-11 21:11:46 +00:00
|
|
|
const { answer, items, contract, type, betsByCurrentUser, comments } = props
|
2022-03-15 20:11:14 +00:00
|
|
|
const { username, avatarUrl, name, text } = answer
|
2022-05-11 21:11:46 +00:00
|
|
|
const user = useUser()
|
|
|
|
const mostRecentCommentableBet = getMostRecentCommentableBet(
|
|
|
|
betsByCurrentUser ?? [],
|
|
|
|
comments ?? [],
|
|
|
|
user,
|
|
|
|
answer.number + ''
|
|
|
|
)
|
2022-03-17 04:42:24 +00:00
|
|
|
const prob = getDpmOutcomeProbability(contract.totalShares, answer.id)
|
|
|
|
const probPercent = formatPercent(prob)
|
|
|
|
const [open, setOpen] = useState(false)
|
2022-05-11 21:11:46 +00:00
|
|
|
const [showReply, setShowReply] = useState(false)
|
|
|
|
const isFreeResponseContractPage = type === 'answergroup' && comments
|
|
|
|
if (mostRecentCommentableBet && !showReply) setShowReplyAndFocus(true)
|
|
|
|
const [inputRef, setInputRef] = useState<HTMLTextAreaElement | null>(null)
|
|
|
|
|
|
|
|
// If they've already opened the input box, focus it once again
|
|
|
|
function setShowReplyAndFocus(show: boolean) {
|
|
|
|
setShowReply(show)
|
|
|
|
inputRef?.focus()
|
|
|
|
}
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (showReply && inputRef) inputRef.focus()
|
|
|
|
}, [inputRef, showReply])
|
2022-03-17 04:42:24 +00:00
|
|
|
|
2022-03-14 20:29:32 +00:00
|
|
|
return (
|
2022-04-26 13:24:57 +00:00
|
|
|
<Col
|
|
|
|
className={
|
|
|
|
type === 'answer'
|
|
|
|
? 'border-base-200 bg-base-200 flex-1 rounded-md p-3'
|
|
|
|
: 'flex-1 gap-2'
|
|
|
|
}
|
|
|
|
>
|
2022-03-17 04:42:24 +00:00
|
|
|
<Modal open={open} setOpen={setOpen}>
|
|
|
|
<AnswerBetPanel
|
|
|
|
answer={answer}
|
|
|
|
contract={contract}
|
|
|
|
closePanel={() => setOpen(false)}
|
|
|
|
className="sm:max-w-84 !rounded-md bg-white !px-8 !py-6"
|
|
|
|
isModal={true}
|
|
|
|
/>
|
|
|
|
</Modal>
|
|
|
|
|
2022-03-15 20:11:14 +00:00
|
|
|
<Row className="my-4 gap-3">
|
2022-03-14 20:29:32 +00:00
|
|
|
<div className="px-1">
|
2022-05-09 21:32:59 +00:00
|
|
|
<Avatar username={username} avatarUrl={avatarUrl} />
|
2022-03-14 20:29:32 +00:00
|
|
|
</div>
|
2022-05-11 21:11:46 +00:00
|
|
|
<Col className="min-w-0 flex-1 lg:gap-1">
|
2022-03-14 20:29:32 +00:00
|
|
|
<div className="text-sm text-gray-500">
|
2022-03-15 19:22:21 +00:00
|
|
|
<UserLink username={username} name={name} /> answered
|
2022-03-14 20:29:32 +00:00
|
|
|
</div>
|
2022-03-17 04:42:24 +00:00
|
|
|
|
2022-04-18 23:02:40 +00:00
|
|
|
<Col className="align-items justify-between gap-4 sm:flex-row">
|
2022-03-25 16:27:28 +00:00
|
|
|
<span className="whitespace-pre-line text-lg">
|
2022-03-17 04:42:24 +00:00
|
|
|
<Linkify text={text} />
|
|
|
|
</span>
|
|
|
|
|
2022-05-11 21:11:46 +00:00
|
|
|
<Row className="items-center justify-center gap-4">
|
|
|
|
{isFreeResponseContractPage && (
|
|
|
|
<div className={'sm:hidden'}>
|
|
|
|
<button
|
|
|
|
className={
|
2022-05-12 16:27:25 +00:00
|
|
|
'text-xs font-bold text-gray-500 hover:underline'
|
2022-05-11 21:11:46 +00:00
|
|
|
}
|
|
|
|
onClick={() => setShowReplyAndFocus(true)}
|
|
|
|
>
|
|
|
|
Reply
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
)}
|
|
|
|
|
|
|
|
<div className={'align-items flex w-full justify-end gap-4 '}>
|
|
|
|
<span
|
|
|
|
className={clsx(
|
|
|
|
'text-2xl',
|
|
|
|
tradingAllowed(contract)
|
|
|
|
? 'text-green-500'
|
|
|
|
: 'text-gray-500'
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{probPercent}
|
|
|
|
</span>
|
|
|
|
<BuyButton
|
|
|
|
className={clsx(
|
|
|
|
'btn-sm flex-initial !px-6 sm:flex',
|
|
|
|
tradingAllowed(contract) ? '' : '!hidden'
|
|
|
|
)}
|
|
|
|
onClick={() => setOpen(true)}
|
|
|
|
/>
|
|
|
|
</div>
|
2022-03-17 04:42:24 +00:00
|
|
|
</Row>
|
2022-04-18 23:02:40 +00:00
|
|
|
</Col>
|
2022-05-11 21:11:46 +00:00
|
|
|
{isFreeResponseContractPage && (
|
|
|
|
<div className={'justify-initial hidden sm:block'}>
|
|
|
|
<button
|
2022-05-12 16:27:25 +00:00
|
|
|
className={'text-xs font-bold text-gray-500 hover:underline'}
|
2022-05-11 21:11:46 +00:00
|
|
|
onClick={() => setShowReplyAndFocus(true)}
|
|
|
|
>
|
|
|
|
Reply
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
)}
|
2022-03-14 20:29:32 +00:00
|
|
|
</Col>
|
|
|
|
</Row>
|
|
|
|
|
|
|
|
{items.map((item, index) => (
|
|
|
|
<div
|
|
|
|
key={item.id}
|
|
|
|
className={clsx(
|
|
|
|
'relative ml-8',
|
|
|
|
index !== items.length - 1 && 'pb-4'
|
|
|
|
)}
|
|
|
|
>
|
|
|
|
{index !== items.length - 1 ? (
|
|
|
|
<span
|
|
|
|
className="absolute top-5 left-5 -ml-px h-[calc(100%-1rem)] w-0.5 bg-gray-200"
|
|
|
|
aria-hidden="true"
|
|
|
|
/>
|
|
|
|
) : null}
|
|
|
|
<div className="relative flex items-start space-x-3">
|
|
|
|
<FeedItem item={item} />
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
))}
|
2022-05-12 14:59:05 +00:00
|
|
|
|
|
|
|
{showReply && (
|
2022-05-12 16:27:25 +00:00
|
|
|
<div className={'ml-8 pt-4'}>
|
2022-05-12 14:59:05 +00:00
|
|
|
<CommentInput
|
|
|
|
contract={contract}
|
|
|
|
betsByCurrentUser={betsByCurrentUser ?? []}
|
|
|
|
comments={comments ?? []}
|
|
|
|
answerOutcome={answer.number + ''}
|
|
|
|
replyToUsername={answer.username}
|
|
|
|
setRef={setInputRef}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
)}
|
2022-03-14 20:29:32 +00:00
|
|
|
</Col>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-01-22 17:46:59 +00:00
|
|
|
// TODO: Should highlight the entire Feed segment
|
|
|
|
function FeedExpand(props: { setExpanded: (expanded: boolean) => void }) {
|
|
|
|
const { setExpanded } = props
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<button onClick={() => setExpanded(true)}>
|
|
|
|
<div className="relative px-1">
|
2022-02-11 18:40:22 +00:00
|
|
|
<div className="flex h-8 w-8 items-center justify-center rounded-full bg-gray-200 hover:bg-gray-300">
|
2022-01-22 17:46:59 +00:00
|
|
|
<DotsVerticalIcon
|
|
|
|
className="h-5 w-5 text-gray-500"
|
|
|
|
aria-hidden="true"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</button>
|
|
|
|
|
|
|
|
<button onClick={() => setExpanded(true)}>
|
|
|
|
<div className="min-w-0 flex-1 py-1.5">
|
|
|
|
<div className="text-sm text-gray-500 hover:text-gray-700">
|
|
|
|
<span>Show all activity</span>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</button>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|