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
4.9 KiB
TypeScript
164 lines
4.9 KiB
TypeScript
import clsx from 'clsx'
|
|
import { Bet } from 'common/bet'
|
|
import { ContractComment } from 'common/comment'
|
|
import { Contract } from 'common/contract'
|
|
import { useState } from 'react'
|
|
import { toast } from 'react-hot-toast'
|
|
import { BiRepost } from 'react-icons/bi'
|
|
import { Button, SizeType } from 'web/components/buttons/button'
|
|
import {
|
|
CommentReplyHeader,
|
|
CommentReplyHeaderWithBet,
|
|
FeedCommentHeader,
|
|
} from 'web/components/comments/comment-header'
|
|
import { ContractCommentInput } from 'web/components/comments/comment-input'
|
|
import { Col } from 'web/components/layout/col'
|
|
import { Modal } from 'web/components/layout/modal'
|
|
import { Avatar } from 'web/components/widgets/avatar'
|
|
import { Content } from 'web/components/widgets/editor'
|
|
import { Tooltip } from 'web/components/widgets/tooltip'
|
|
import { api } from 'web/lib/api/api'
|
|
import { Row } from '../layout/row'
|
|
import { UserHovercard } from '../user/user-hovercard'
|
|
|
|
export const RepostButton = (props: {
|
|
playContract: Contract
|
|
bet?: Bet
|
|
size: SizeType
|
|
className?: string
|
|
iconClassName?: string
|
|
}) => {
|
|
const { playContract, bet, size, className, iconClassName } = props
|
|
const [open, setOpen] = useState(false)
|
|
return (
|
|
<>
|
|
<Tooltip
|
|
text="Repost with comment to followers"
|
|
placement="bottom"
|
|
noTap
|
|
className="flex select-none items-center"
|
|
>
|
|
<Button
|
|
color={'gray-white'}
|
|
size={size}
|
|
className={clsx(className)}
|
|
onClick={() => setOpen(true)}
|
|
>
|
|
<BiRepost className={clsx(iconClassName, 'h-6 w-6')} />
|
|
</Button>
|
|
</Tooltip>
|
|
{open && (
|
|
<RepostModal
|
|
bet={bet}
|
|
playContract={playContract}
|
|
open={open}
|
|
setOpen={setOpen}
|
|
/>
|
|
)}
|
|
</>
|
|
)
|
|
}
|
|
|
|
export const RepostModal = (props: {
|
|
playContract: Contract
|
|
bet?: Bet
|
|
comment?: ContractComment
|
|
open: boolean
|
|
setOpen: (open: boolean) => void
|
|
}) => {
|
|
const { playContract, comment, bet, open, setOpen } = props
|
|
const [loading, setLoading] = useState(false)
|
|
const repost = async () =>
|
|
api('post', {
|
|
contractId: playContract.id,
|
|
commentId: comment?.id,
|
|
betId: bet?.id,
|
|
})
|
|
.then(() => toast.success('Reposted to your followers!'))
|
|
.catch((e: Error) => {
|
|
toast.error(e.message)
|
|
})
|
|
|
|
const commenterIsBettor = comment?.userId === bet?.userId
|
|
return (
|
|
<Modal
|
|
open={open}
|
|
setOpen={setOpen}
|
|
className={'bg-canvas-0 text-ink-1000 gap-4 rounded-md px-4 pb-4 sm:px-6'}
|
|
>
|
|
<Col className={'w-full'}>
|
|
<span className={'text-primary-700 mb-4 pt-3 text-lg'}>
|
|
Repost to your followers
|
|
</span>
|
|
{comment ? (
|
|
<Col>
|
|
{((bet && !commenterIsBettor) ||
|
|
(comment.bettorUsername && !commenterIsBettor)) &&
|
|
(bet ? (
|
|
<CommentReplyHeaderWithBet
|
|
contract={playContract}
|
|
comment={comment}
|
|
bet={bet}
|
|
/>
|
|
) : (
|
|
<CommentReplyHeader comment={comment} contract={playContract} />
|
|
))}
|
|
<Row className={'gap-1'}>
|
|
<UserHovercard userId={comment.userId}>
|
|
<Avatar
|
|
username={comment.userUsername}
|
|
size={'sm'}
|
|
avatarUrl={comment.userAvatarUrl}
|
|
className={clsx('z-10 mt-1')}
|
|
/>
|
|
</UserHovercard>
|
|
<Col
|
|
className={clsx(
|
|
'grow rounded-lg rounded-tl-none px-3 pb-0.5 pt-1 transition-colors',
|
|
'bg-canvas-50'
|
|
)}
|
|
>
|
|
<FeedCommentHeader
|
|
comment={comment}
|
|
playContract={playContract}
|
|
inTimeline={false}
|
|
isParent={true}
|
|
/>
|
|
|
|
<Content size="sm" content={comment.content} />
|
|
</Col>
|
|
</Row>
|
|
<Row className={'mt-4 justify-between'}>
|
|
<Button color={'gray'} size={'sm'} onClick={() => setOpen(false)}>
|
|
Cancel
|
|
</Button>
|
|
<Button
|
|
size={'sm'}
|
|
loading={loading}
|
|
disabled={loading}
|
|
onClick={async () => {
|
|
setLoading(true)
|
|
await repost()
|
|
.then(() => setOpen(false))
|
|
.finally(() => setLoading(false))
|
|
}}
|
|
>
|
|
Repost
|
|
</Button>
|
|
</Row>
|
|
</Col>
|
|
) : (
|
|
<ContractCommentInput
|
|
autoFocus
|
|
replyTo={bet}
|
|
playContract={playContract}
|
|
trackingLocation={'contract page'}
|
|
commentTypes={['repost']}
|
|
onClearInput={() => setOpen(false)}
|
|
/>
|
|
)}
|
|
</Col>
|
|
</Modal>
|
|
)
|
|
}
|