Working tree is now the canonical repo. Off-chain play-money + trustless on-chain (FPMM AMM + CLOB via UMA settlement), AI market factory, creator/social/distribution, mobile shell + push, one-command demo + deploy-kit. Secrets excluded (see ENV-AND-KEYS.md). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
164 lines
5.1 KiB
TypeScript
164 lines
5.1 KiB
TypeScript
import { useEvent } from 'client-common/hooks/use-event'
|
|
import clsx from 'clsx'
|
|
import { Bet } from 'common/bet'
|
|
import { ContractComment } from 'common/comment'
|
|
import { Contract } from 'common/contract'
|
|
import { uniq } from 'lodash'
|
|
import { useMemo, useState } from 'react'
|
|
import TriangleDownFillIcon from 'web/lib/icons/triangle-down-fill-icon.svg'
|
|
import TriangleFillIcon from 'web/lib/icons/triangle-fill-icon.svg'
|
|
import { Button } from '../buttons/button'
|
|
import { Col } from '../layout/col'
|
|
import { Row } from '../layout/row'
|
|
import {
|
|
FeedComment,
|
|
ParentFeedComment,
|
|
ReplyToUserInfo,
|
|
roundThreadColor,
|
|
} from './comment'
|
|
import { ContractCommentInput } from './comment-input'
|
|
|
|
export function FeedCommentThread(props: {
|
|
playContract: Contract
|
|
liveContract: Contract
|
|
threadComments: ContractComment[]
|
|
parentComment: ContractComment
|
|
trackingLocation: string
|
|
collapseMiddle?: boolean
|
|
inTimeline?: boolean
|
|
idInUrl?: string
|
|
showReplies?: boolean
|
|
childrenBountyTotal?: number
|
|
className?: string
|
|
bets?: Bet[]
|
|
blockedUserIds?: string[]
|
|
}) {
|
|
const {
|
|
playContract,
|
|
liveContract,
|
|
threadComments,
|
|
parentComment,
|
|
collapseMiddle,
|
|
trackingLocation,
|
|
inTimeline,
|
|
idInUrl,
|
|
showReplies,
|
|
childrenBountyTotal,
|
|
className,
|
|
bets,
|
|
blockedUserIds,
|
|
} = props
|
|
const [replyToUserInfo, setReplyToUserInfo] = useState<ReplyToUserInfo>()
|
|
|
|
const idInThisThread =
|
|
idInUrl && threadComments.map((comment) => comment.id).includes(idInUrl)
|
|
|
|
const [seeReplies, setSeeReplies] = useState(
|
|
!parentComment.hidden && (showReplies || !!idInThisThread)
|
|
)
|
|
|
|
const onSeeRepliesClick = useEvent(() => setSeeReplies(!seeReplies))
|
|
const clearReply = useEvent(() => setReplyToUserInfo(undefined))
|
|
const onReplyClick = useEvent((comment: ContractComment) => {
|
|
setSeeReplies(true)
|
|
setReplyToUserInfo({ id: comment.id, username: comment.userUsername })
|
|
})
|
|
const [collapseToIndex, setCollapseToIndex] = useState<number>(
|
|
collapseMiddle && threadComments.length > 2
|
|
? threadComments.length - 2
|
|
: Infinity
|
|
)
|
|
|
|
// Get thread participant user IDs for mention prioritization (parent author first, then replies)
|
|
const threadUserIds = useMemo(
|
|
() =>
|
|
uniq([
|
|
parentComment.userId,
|
|
...threadComments.map((c) => c.userId),
|
|
]).filter((id) => id !== playContract.creatorId),
|
|
[parentComment.userId, threadComments, playContract.creatorId]
|
|
)
|
|
|
|
return (
|
|
<Col className={clsx('mt-3 items-stretch gap-3', className)}>
|
|
<ParentFeedComment
|
|
key={parentComment.id}
|
|
playContract={playContract}
|
|
liveContract={liveContract}
|
|
comment={parentComment}
|
|
highlighted={idInUrl === parentComment.id}
|
|
seeReplies={seeReplies}
|
|
numReplies={threadComments.length}
|
|
onSeeReplyClick={onSeeRepliesClick}
|
|
onReplyClick={onReplyClick}
|
|
trackingLocation={trackingLocation}
|
|
inTimeline={inTimeline}
|
|
childrenBountyTotal={childrenBountyTotal}
|
|
bets={bets?.filter((bet) => bet.replyToCommentId === parentComment.id)}
|
|
blockedUserIds={blockedUserIds}
|
|
/>
|
|
{seeReplies &&
|
|
threadComments
|
|
.slice(0, collapseToIndex)
|
|
.map((comment, i) => (
|
|
<FeedComment
|
|
key={comment.id}
|
|
playContract={playContract}
|
|
liveContract={liveContract}
|
|
comment={comment}
|
|
highlighted={idInUrl === comment.id}
|
|
onReplyClick={onReplyClick}
|
|
trackingLocation={trackingLocation}
|
|
bets={bets?.filter((bet) => bet.replyToCommentId === comment.id)}
|
|
lastInReplyChain={i === threadComments.length - 1}
|
|
blockedUserIds={blockedUserIds}
|
|
/>
|
|
))}
|
|
{seeReplies && threadComments.length > collapseToIndex && (
|
|
<Row
|
|
className={'justify-end sm:-mb-2 sm:mt-1'}
|
|
key={parentComment.id + 'see-replies-feed-button'}
|
|
>
|
|
<Button
|
|
size={'xs'}
|
|
color={'gray-white'}
|
|
onClick={() => {
|
|
setCollapseToIndex(Infinity)
|
|
}}
|
|
>
|
|
<Col>
|
|
<TriangleFillIcon className={'mr-2 h-2'} />
|
|
<TriangleDownFillIcon className={'mr-2 h-2'} />
|
|
</Col>
|
|
See {threadComments.length - 1} replies
|
|
</Button>
|
|
</Row>
|
|
)}
|
|
|
|
<div
|
|
className={clsx('stop-prop flex', replyToUserInfo ? 'block' : 'hidden')}
|
|
>
|
|
<div
|
|
className={clsx(
|
|
roundThreadColor,
|
|
'-mt-3 ml-4 h-7 w-4 rounded-bl-xl border-b-2 border-l-2'
|
|
)}
|
|
/>
|
|
{replyToUserInfo && (
|
|
<ContractCommentInput
|
|
playContract={playContract}
|
|
parentCommentId={parentComment.id}
|
|
replyToUserInfo={replyToUserInfo}
|
|
clearReply={clearReply}
|
|
trackingLocation={trackingLocation}
|
|
className="w-full min-w-0 grow"
|
|
commentTypes={['comment']}
|
|
autoFocus
|
|
commenterUserIds={threadUserIds}
|
|
/>
|
|
)}
|
|
</div>
|
|
</Col>
|
|
)
|
|
}
|