I've merged and now it's a mess

This commit is contained in:
ingawei 2022-10-11 20:29:17 -07:00
parent 89fcbaeb07
commit 015e3ef24c
2 changed files with 87 additions and 139 deletions

View File

@ -13,6 +13,7 @@ import { useUser } from 'web/hooks/use-user'
import { useEvent } from 'web/hooks/use-event' import { useEvent } from 'web/hooks/use-event'
import { CommentTipMap } from 'web/hooks/use-tip-txns' import { CommentTipMap } from 'web/hooks/use-tip-txns'
import { UserLink } from 'web/components/user-link' import { UserLink } from 'web/components/user-link'
import { ReplyTo } from './feed-comments'
export function CommentsAnswer(props: { answer: Answer; contract: Contract }) { export function CommentsAnswer(props: { answer: Answer; contract: Contract }) {
const { answer, contract } = props const { answer, contract } = props
@ -21,15 +22,9 @@ export function CommentsAnswer(props: { answer: Answer; contract: Contract }) {
const [replyTo, setReplyTo] = useState<ReplyTo>() const [replyTo, setReplyTo] = useState<ReplyTo>()
const user = useUser() const user = useUser()
const router = useRouter() const router = useRouter()
const answerElementId = `answer-${answer.id}`
const highlighted = router.asPath.endsWith(`#${answerElementId}`) const highlighted = router.asPath.endsWith(`#${answerElementId}`)
const answerRef = useRef<HTMLDivElement>(null) const answerRef = useRef<HTMLDivElement>(null)
const onSubmitComment = useEvent(() => setReplyTo(undefined))
const onReplyClick = useEvent((comment: ContractComment) => {
setReplyTo({ id: comment.id, username: comment.userUsername })
})
useEffect(() => { useEffect(() => {
if (highlighted && answerRef.current != null) { if (highlighted && answerRef.current != null) {
answerRef.current.scrollIntoView(true) answerRef.current.scrollIntoView(true)
@ -37,77 +32,20 @@ export function CommentsAnswer(props: { answer: Answer; contract: Contract }) {
}, [highlighted]) }, [highlighted])
return ( return (
<Row className="bg-greyscale-2 w-fit gap-1 rounded-t-xl rounded-bl-xl px-2 py-2"> <Col className="bg-greyscale-2 w-fit gap-1 rounded-t-xl rounded-bl-xl py-2 px-4">
<div className="ml-2"> <Row className="gap-2">
<Avatar username={username} avatarUrl={avatarUrl} size="xxs" /> <Avatar username={username} avatarUrl={avatarUrl} size="xxs" />
</div> <div className="text-greyscale-6 text-xs">
<Col> <UserLink username={username} name={name} /> answered
<Row className="gap-1"> <CopyLinkDateTimeComponent
<div className="text-greyscale-6 text-xs"> prefix={contract.creatorUsername}
<UserLink username={username} name={name} /> answered slug={contract.slug}
<CopyLinkDateTimeComponent createdTime={answer.createdTime}
prefix={contract.creatorUsername} elementId={answerElementId}
slug={contract.slug}
createdTime={answer.createdTime}
elementId={answerElementId}
/>
</div>
<Col className="align-items justify-between gap-2 sm:flex-row">
<span className="whitespace-pre-line text-lg">
<Linkify text={text} />
</span>
<div className="sm:hidden">
<button
className="text-xs font-bold text-gray-500 hover:underline"
onClick={() =>
setReplyTo({ id: answer.id, username: answer.username })
}
>
Reply
</button>
</div>
</Col>
<div className="justify-initial hidden sm:block">
<button
className="text-xs font-bold text-gray-500 hover:underline"
onClick={() =>
setReplyTo({ id: answer.id, username: answer.username })
}
>
Reply
</button>
</div>
</Col>
</Row>
<Col className="gap-3 pl-1">
{answerComments.map((comment) => (
<FeedComment
key={comment.id}
indent={true}
contract={contract}
comment={comment}
myTip={user ? tips[comment.id]?.[user.id] : undefined}
totalTip={sum(Object.values(tips[comment.id] ?? {}))}
showTip={true}
onReplyClick={onReplyClick}
/>
))}
</Col>
{replyTo && (
<div className="relative ml-7">
<span
className="absolute -left-1 -ml-[1px] mt-[1.25rem] h-2 w-0.5 rotate-90 bg-gray-200"
aria-hidden="true"
/>
<ContractCommentInput
contract={contract}
parentAnswerOutcome={answer.number.toString()}
replyTo={replyTo}
onSubmitComment={onSubmitComment}
/> />
</div> </div>
)} </Row>
<div className="text-sm">{answer.text}</div>
</Col> </Col>
) )
} }

View File

@ -6,8 +6,6 @@ import clsx from 'clsx'
import { ContractComment } from 'common/comment' import { ContractComment } from 'common/comment'
import { AnyContractType, Contract } from 'common/contract' import { AnyContractType, Contract } from 'common/contract'
import React, { useEffect, useRef, useState } from 'react'
import { Contract } from 'common/contract'
import { useUser } from 'web/hooks/use-user' import { useUser } from 'web/hooks/use-user'
import { formatMoney } from 'common/util/format' import { formatMoney } from 'common/util/format'
import { Row } from 'web/components/layout/row' import { Row } from 'web/components/layout/row'
@ -49,35 +47,33 @@ export function FeedCommentThread(props: {
return ( return (
<Col className="relative w-full items-stretch gap-3 pb-4"> <Col className="relative w-full items-stretch gap-3 pb-4">
<Col> <ParentFeedComment
<ParentFeedComment key={parentComment.id}
key={parentComment.id} contract={contract}
contract={contract} comment={parentComment}
comment={parentComment} myTip={user ? tips[parentComment.id]?.[user.id] : undefined}
myTip={user ? tips[parentComment.id]?.[user.id] : undefined} totalTip={sum(Object.values(tips[parentComment.id] ?? {}))}
showTip={true} showTip={true}
totalTip={sum(Object.values(tips[parentComment.id] ?? {}))} seeReplies={seeReplies}
seeReplies={seeReplies} numComments={threadComments.length}
numComments={threadComments.length} onSeeReplyClick={() => setSeeReplies(!seeReplies)}
onSeeReplyClick={() => setSeeReplies(!seeReplies)} onReplyClick={() =>
onReplyClick={() => setReplyTo({
setReplyTo({ id: parentComment.id,
id: parentComment.id, username: parentComment.userUsername,
username: parentComment.userUsername, })
}) }
} />
/>
</Col>
{seeReplies && {seeReplies &&
threadComments.map((comment, _commentIdx) => ( threadComments.map((comment, _commentIdx) => (
<FeedComment <FeedComment
key={comment.id} key={comment.id}
contract={contract} contract={contract}
comment={comment} comment={comment}
tips={tips[comment.id] ?? {}} myTip={user ? tips[comment.id]?.[user.id] : undefined}
onReplyClick={() => totalTip={sum(Object.values(tips[comment.id] ?? {}))}
setReplyTo({ id: comment.id, username: comment.userUsername }) showTip={true}
} onReplyClick={onReplyClick}
/> />
))} ))}
{replyTo && ( {replyTo && (
@ -97,19 +93,24 @@ export function FeedCommentThread(props: {
</Col> </Col>
) )
} }
export function ParentFeedComment(props: { export function ParentFeedComment(props: {
contract: Contract contract: Contract
comment: ContractComment comment: ContractComment
tips?: CommentTips showTip?: boolean
myTip?: number
totalTip?: number
seeReplies: boolean seeReplies: boolean
numComments: number numComments: number
onReplyClick?: () => void onReplyClick?: (comment: ContractComment) => void
onSeeReplyClick: () => void onSeeReplyClick: () => void
}) { }) {
const { const {
contract, contract,
comment, comment,
tips, myTip,
totalTip,
showTip,
onReplyClick, onReplyClick,
onSeeReplyClick, onSeeReplyClick,
seeReplies, seeReplies,
@ -154,12 +155,24 @@ export function ParentFeedComment(props: {
onClick={onSeeReplyClick} onClick={onSeeReplyClick}
/> />
<Row className="grow justify-end"> <Row className="grow justify-end">
<CommentActions {onReplyClick && (
onReplyClick={onReplyClick} <button
tips={tips} className="font-bold hover:underline"
comment={comment} onClick={() => onReplyClick(comment)}
contract={contract} >
/> Reply
</button>
)}
{showTip && (
<Tipper
comment={comment}
myTip={myTip ?? 0}
totalTip={totalTip ?? 0}
/>
)}
{(contract.openCommentBounties ?? 0) > 0 && (
<AwardBountyButton comment={comment} contract={contract} />
)}
</Row> </Row>
</Row> </Row>
</Col> </Col>
@ -173,11 +186,9 @@ export const FeedComment = memo(function FeedComment(props: {
showTip?: boolean showTip?: boolean
myTip?: number myTip?: number
totalTip?: number totalTip?: number
indent?: boolean
onReplyClick?: (comment: ContractComment) => void onReplyClick?: (comment: ContractComment) => void
}) { }) {
const { contract, comment, myTip, totalTip, showTip, indent, onReplyClick } = const { contract, comment, myTip, totalTip, showTip, onReplyClick } = props
props
const { const {
text, text,
content, content,
@ -233,7 +244,6 @@ export const FeedComment = memo(function FeedComment(props: {
</Col> </Col>
<Col className="w-full"> <Col className="w-full">
<FeedCommentHeader comment={comment} contract={contract} /> <FeedCommentHeader comment={comment} contract={contract} />
{/* TODO: bug where if this is iFrame, it does not scroll */}
<Content <Content
className="text-greyscale-7 mt-2 grow text-[14px]" className="text-greyscale-7 mt-2 grow text-[14px]"
content={content || text} content={content || text}
@ -262,35 +272,35 @@ export const FeedComment = memo(function FeedComment(props: {
</Col> </Col>
</Row> </Row>
) )
}
export function CommentActions(props: {
onReplyClick?: () => void
tips?: CommentTips | undefined
comment: ContractComment
contract: Contract<AnyContractType>
}) {
const { onReplyClick, tips, comment, contract } = props
return (
<Row className={clsx('ml-2 items-center gap-2 text-xs text-gray-500')}>
{onReplyClick && (
<Button
className="font-bold hover:underline"
onClick={onReplyClick}
size="2xs"
color="gray-white"
>
<ReplyIcon className="h-5 w-5" />
</Button>
)}
{tips && <Tipper comment={comment} tips={tips} />}
{(contract.openCommentBounties ?? 0) > 0 && (
<AwardBountyButton comment={comment} contract={contract} />
)}
</Row>
)
}) })
// export function CommentActions(props: {
// onReplyClick?: () => void
// tips?: CommentTips | undefined
// comment: ContractComment
// contract: Contract<AnyContractType>
// }) {
// const { onReplyClick, tips, comment, contract } = props
// return (
// <Row className={clsx('ml-2 items-center gap-2 text-xs text-gray-500')}>
// {onReplyClick && (
// <Button
// className="font-bold hover:underline"
// onClick={onReplyClick}
// size="2xs"
// color="gray-white"
// >
// <ReplyIcon className="h-5 w-5" />
// </Button>
// )}
// {tips && <Tipper comment={comment} tips={tips} />}
// {(contract.openCommentBounties ?? 0) > 0 && (
// <AwardBountyButton comment={comment} contract={contract} />
// )}
// </Row>
// )
// })
function CommentStatus(props: { function CommentStatus(props: {
contract: Contract contract: Contract
outcome: string outcome: string