Skip to content

Commit

Permalink
Fix answers not showing on comments (#2890)
Browse files Browse the repository at this point in the history
prop-thread play market (comments) and live market (bets, answers)
through ALL comment components 🍝πŸ’ͺ
unfortunately this will increase rerenders

delete old main contract page and old header
  • Loading branch information
sipec authored Sep 20, 2024
1 parent a8f058e commit 655d54c
Show file tree
Hide file tree
Showing 17 changed files with 179 additions and 800 deletions.
8 changes: 0 additions & 8 deletions web/components/bet/user-bets-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -653,14 +653,6 @@ function BetsTable(props: {
)
}

const getChange = (c: CPMMContract): string | undefined => {
const probChange = Math.round((c as CPMMContract).probChanges.day * 100)
return probChange !== 0
? (probChange > 0 ? '+' : '') +
probChange +
(c.outcomeType === 'BINARY' ? '' : '%')
: ''
}
const MAX_SHOWN_MOBILE = 5
const columnsToDisplay = dataColumns
.filter((c) => isEnabled(c.header.sort))
Expand Down
19 changes: 10 additions & 9 deletions web/components/comments/comment-actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,19 @@ export function CommentActions(props: {
onReplyClick?: (comment: ContractComment) => void
onAward?: (bountyTotal: number) => void
comment: ContractComment
contract: Contract
liveContract: Contract // NOT the main contract that has the comments. this is for bets/bounty
trackingLocation: string
}) {
const { onReplyClick, onAward, comment, contract, trackingLocation } = props
const { onReplyClick, onAward, comment, liveContract, trackingLocation } =
props
const user = useUser()
const privateUser = usePrivateUser()

const isBountiedQuestion = contract.outcomeType === 'BOUNTIED_QUESTION'
const isBountiedQuestion = liveContract.outcomeType === 'BOUNTIED_QUESTION'
const canGiveBounty =
isBountiedQuestion &&
user &&
user.id == contract.creatorId &&
user.id == liveContract.creatorId &&
comment.userId != user.id &&
onAward
const [showBetModal, setShowBetModal] = useState(false)
Expand All @@ -41,21 +42,21 @@ export function CommentActions(props: {
(comment.betReplyAmountsByOutcome?.YES ?? 0) -
(comment.betReplyAmountsByOutcome?.NO ?? 0)

const isCashContract = contract.token === 'CASH'
const isCashContract = liveContract.token === 'CASH'

return (
<Row className="grow items-center justify-end">
{canGiveBounty && (
<AwardBountyButton
contract={contract}
contract={liveContract}
comment={comment}
onAward={onAward}
user={user}
disabled={contract.bountyLeft <= 0}
disabled={liveContract.bountyLeft <= 0}
buttonClassName={'mr-1'}
/>
)}
{user && contract.outcomeType === 'BINARY' && !isCashContract && (
{user && liveContract.outcomeType === 'BINARY' && !isCashContract && (
<IconButton
onClick={() => {
// TODO: Twomba tracking bet terminology
Expand Down Expand Up @@ -120,7 +121,7 @@ export function CommentActions(props: {
@{comment.userUsername}: {richTextToString(comment.content)}
</span>
<BuyPanel
contract={contract as any}
contract={liveContract as any}
initialOutcome={outcome}
onBuySuccess={() => setTimeout(() => setShowBetModal(false), 500)}
location={'comment on contract'}
Expand Down
83 changes: 47 additions & 36 deletions web/components/comments/comment-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,23 @@ import { RepostModal } from './repost-modal'

export function FeedCommentHeader(props: {
comment: ContractComment
contract: Contract
playContract: Contract
liveContract: Contract
updateComment?: (comment: Partial<ContractComment>) => void
inTimeline?: boolean
isParent?: boolean
isPinned?: boolean
className?: string
}) {
const { comment, updateComment, contract, inTimeline, isPinned, className } =
props
const {
comment,
updateComment,
playContract,
liveContract,
inTimeline,
isPinned,
className,
} = props
const {
userUsername,
userName,
Expand All @@ -78,7 +86,7 @@ export function FeedCommentHeader(props: {
} = comment

const betOnCashContract = betToken === 'CASH'
const marketCreator = contract.creatorId === userId
const marketCreator = playContract.creatorId === userId
const { bought, money } = getBoughtMoney(betAmount, betOnCashContract)
const shouldDisplayOutcome = betOutcome && !answerOutcome
const isReplyToBet = betAmount !== undefined
Expand Down Expand Up @@ -112,7 +120,7 @@ export function FeedCommentHeader(props: {
<OutcomeLabel
outcome={betOutcome ? betOutcome : ''}
answerId={betAnswerId}
contract={contract}
contract={liveContract}
truncate="short"
/>{' '}
at {formatPercent(betLimitProb)} order
Expand All @@ -123,7 +131,7 @@ export function FeedCommentHeader(props: {
<OutcomeLabel
outcome={betOutcome ? betOutcome : ''}
answerId={betAnswerId}
contract={contract}
contract={liveContract}
truncate="short"
/>
</span>
Expand All @@ -139,7 +147,7 @@ export function FeedCommentHeader(props: {
{/* Hide my status if replying to a bet, it's too much clutter*/}
{!isReplyToBet && !inTimeline && (
<span className="text-ink-500">
<CommentStatus contract={contract} comment={comment} />
<CommentStatus contract={liveContract} comment={comment} />
{bought} {money}
{shouldDisplayOutcome && (
<>
Expand All @@ -148,7 +156,7 @@ export function FeedCommentHeader(props: {
<OutcomeLabel
outcome={betOutcome ? betOutcome : ''}
answerId={betAnswerId}
contract={contract}
contract={liveContract}
truncate="short"
/>
</>
Expand All @@ -159,8 +167,8 @@ export function FeedCommentHeader(props: {
<CommentEditHistoryButton comment={comment} />
) : (
<CopyLinkDateTimeComponent
prefix={contract.creatorUsername}
slug={contract.slug}
prefix={playContract.creatorUsername}
slug={playContract.slug}
createdTime={editedTime ? editedTime : createdTime}
elementId={comment.id}
size={'sm'}
Expand All @@ -174,7 +182,8 @@ export function FeedCommentHeader(props: {
<DotMenu
updateComment={updateComment}
comment={comment}
contract={contract}
playContract={playContract}
liveContract={liveContract}
/>
)}
</Row>
Expand All @@ -184,7 +193,7 @@ export function FeedCommentHeader(props: {
+
<MoneyDisplay
amount={bountyAwarded}
isCashContract={contract.token === 'CASH'}
isCashContract={liveContract.token === 'CASH'}
/>
</span>
)}
Expand Down Expand Up @@ -214,9 +223,9 @@ const getBoughtMoney = (
export function CommentReplyHeaderWithBet(props: {
comment: ContractComment
bet: Bet
contract: Contract
liveContract: Contract
}) {
const { comment, bet, contract } = props
const { comment, bet, liveContract } = props
const { outcome, answerId, amount, orderAmount, limitProb } = bet
return (
<CommentReplyHeader
Expand All @@ -228,17 +237,17 @@ export function CommentReplyHeaderWithBet(props: {
betLimitProb: limitProb,
answerOutcome: answerId,
}}
contract={contract}
liveContract={liveContract}
/>
)
}

export function CommentReplyHeader(props: {
comment: ContractComment
contract: Contract
liveContract: Contract
hideBetHeader?: boolean
}) {
const { comment, contract, hideBetHeader } = props
const { comment, liveContract, hideBetHeader } = props
const {
bettorName,
bettorId,
Expand Down Expand Up @@ -267,20 +276,20 @@ export function CommentReplyHeader(props: {
betAmount={betAmount}
betOrderAmount={betOrderAmount}
betLimitProb={betLimitProb}
contract={contract}
liveContract={liveContract}
/>
)
}
if (answerOutcome && 'answers' in contract) {
const answer = contract.answers.find((a) => a.id === answerOutcome)
if (answerOutcome && 'answers' in liveContract) {
const answer = liveContract.answers.find((a) => a.id === answerOutcome)
if (answer) return <CommentOnAnswer answer={answer} />
}

return null
}

export function ReplyToBetRow(props: {
contract: Contract
liveContract: Contract
commenterIsBettor: boolean
betOutcome: string
betAmount: number
Expand All @@ -300,7 +309,7 @@ export function ReplyToBetRow(props: {
bettorName,
bettorId,
betAnswerId,
contract,
liveContract: contract,
clearReply,
betLimitProb,
betOrderAmount,
Expand Down Expand Up @@ -432,14 +441,15 @@ function CommentStatus(props: {
export function DotMenu(props: {
comment: ContractComment
updateComment: (update: Partial<ContractComment>) => void
contract: Contract
playContract: Contract
liveContract: Contract
}) {
const { comment, updateComment, contract } = props
const { comment, updateComment, playContract, liveContract } = props
const [isModalOpen, setIsModalOpen] = useState(false)
const user = useUser()
const privateUser = usePrivateUser()
const isMod = useAdminOrMod()
const isContractCreator = privateUser?.id === contract.creatorId
const isContractCreator = privateUser?.id === playContract.creatorId
const [editingComment, setEditingComment] = useState(false)
const [tipping, setTipping] = useState(false)
const [reposting, setReposting] = useState(false)
Expand All @@ -451,7 +461,7 @@ export function DotMenu(props: {
contentOwnerId: comment.userId,
contentId: comment.id,
contentType: 'comment',
parentId: contract.id,
parentId: playContract.id,
parentType: 'contract',
}}
setIsModalOpen={setIsModalOpen}
Expand All @@ -472,8 +482,8 @@ export function DotMenu(props: {
icon: <LinkIcon className="h-5 w-5" />,
onClick: () => {
copyLinkToComment(
contract.creatorUsername,
contract.slug,
playContract.creatorUsername,
playContract.slug,
comment.id
)
},
Expand Down Expand Up @@ -513,7 +523,7 @@ export function DotMenu(props: {
name: comment.hidden ? 'Unhide' : 'Hide',
icon: <EyeOffIcon className="h-5 w-5 text-red-500" />,
onClick: async () => {
const commentPath = `contracts/${contract.id}/comments/${comment.id}`
const commentPath = `contracts/${playContract.id}/comments/${comment.id}`
const wasHidden = comment.hidden
updateComment({ hidden: !wasHidden })

Expand All @@ -532,7 +542,7 @@ export function DotMenu(props: {
name: comment.pinned ? 'Unpin' : 'Pin',
icon: <PiPushPinBold className="text-primary-500 h-5 w-5" />,
onClick: async () => {
const commentPath = `contracts/${contract.id}/comments/${comment.id}`
const commentPath = `contracts/${playContract.id}/comments/${comment.id}`
const wasPinned = comment.pinned
updateComment({ pinned: !wasPinned })

Expand All @@ -553,14 +563,15 @@ export function DotMenu(props: {
<AnnotateChartModal
open={annotating}
setOpen={setAnnotating}
contractId={contract.id}
contractId={liveContract.id}
atTime={comment.createdTime}
comment={comment}
/>
)}
{user && reposting && (
<RepostModal
contract={contract}
playContract={playContract}
liveContract={liveContract}
open={reposting}
setOpen={setReposting}
comment={comment}
Expand All @@ -582,7 +593,7 @@ export function DotMenu(props: {
user={user}
comment={comment}
setContent={(content) => updateComment({ content })}
contract={contract}
contract={playContract}
open={editingComment}
setOpen={setEditingComment}
/>
Expand All @@ -600,10 +611,10 @@ export function DotMenu(props: {
show={tipping}
groupId={comment.id}
defaultMessage={`Tip for comment on ${
contract.question
playContract.question
} ${getCommentLink(
contract.creatorUsername,
contract.slug,
playContract.creatorUsername,
playContract.slug,
comment.id
)}`}
/>
Expand Down
Loading

0 comments on commit 655d54c

Please sign in to comment.