Fix free response comment threading

This commit is contained in:
James Grugett 2022-10-02 18:20:25 -05:00
parent 1f8c72b4c9
commit a82f447965
2 changed files with 30 additions and 24 deletions

View File

@ -77,13 +77,34 @@ const CommentsTabContent = memo(function CommentsTabContent(props: {
const comments = useComments(contract.id) ?? props.comments const comments = useComments(contract.id) ?? props.comments
const [sort, setSort] = useState<'Newest' | 'Best'>('Newest') const [sort, setSort] = useState<'Newest' | 'Best'>('Newest')
const me = useUser() const me = useUser()
if (comments == null) { if (comments == null) {
return <LoadingIndicator /> return <LoadingIndicator />
} }
const tipsOrBountiesAwarded =
Object.keys(tips).length > 0 || comments.some((c) => c.bountiesAwarded)
const sortedComments = sortBy(comments, (c) =>
sort === 'Newest'
? c.createdTime
: // Is this too magic? If there are tips/bounties, 'Best' shows your own comments made within the last 10 minutes first, then sorts by score
tipsOrBountiesAwarded &&
c.createdTime > Date.now() - 10 * MINUTE_MS &&
c.userId === me?.id
? -Infinity
: -((c.bountiesAwarded ?? 0) + sum(Object.values(tips[c.id] ?? [])))
)
const commentsByParent = groupBy(
sortedComments,
(c) => c.replyToCommentId ?? '_'
)
const topLevelComments = commentsByParent['_'] ?? []
// Top level comments are reverse-chronological, while replies are chronological
if (sort === 'Newest') topLevelComments.reverse()
if (contract.outcomeType === 'FREE_RESPONSE') { if (contract.outcomeType === 'FREE_RESPONSE') {
const generalComments = comments.filter(
(c) => c.answerOutcome === undefined && c.betId === undefined
)
const sortedAnswers = sortBy( const sortedAnswers = sortBy(
contract.answers, contract.answers,
(a) => -getOutcomeProbability(contract, a.id) (a) => -getOutcomeProbability(contract, a.id)
@ -92,6 +113,9 @@ const CommentsTabContent = memo(function CommentsTabContent(props: {
comments, comments,
(c) => c.answerOutcome ?? c.betOutcome ?? '_' (c) => c.answerOutcome ?? c.betOutcome ?? '_'
) )
const generalTopLevelComments = topLevelComments.filter(
(c) => c.answerOutcome === undefined && c.betId === undefined
)
return ( return (
<> <>
{sortedAnswers.map((answer) => ( {sortedAnswers.map((answer) => (
@ -115,12 +139,12 @@ const CommentsTabContent = memo(function CommentsTabContent(props: {
<div className="text-md mt-8 mb-2 text-left">General Comments</div> <div className="text-md mt-8 mb-2 text-left">General Comments</div>
<div className="mb-4 w-full border-b border-gray-200" /> <div className="mb-4 w-full border-b border-gray-200" />
<ContractCommentInput className="mb-5" contract={contract} /> <ContractCommentInput className="mb-5" contract={contract} />
{generalComments.map((comment) => ( {generalTopLevelComments.map((comment) => (
<FeedCommentThread <FeedCommentThread
key={comment.id} key={comment.id}
contract={contract} contract={contract}
parentComment={comment} parentComment={comment}
threadComments={[]} threadComments={commentsByParent[comment.id] ?? []}
tips={tips} tips={tips}
/> />
))} ))}
@ -128,24 +152,6 @@ const CommentsTabContent = memo(function CommentsTabContent(props: {
</> </>
) )
} else { } else {
const tipsOrBountiesAwarded =
Object.keys(tips).length > 0 || comments.some((c) => c.bountiesAwarded)
const commentsByParent = groupBy(
sortBy(comments, (c) =>
sort === 'Newest'
? -c.createdTime
: // Is this too magic? If there are tips/bounties, 'Best' shows your own comments made within the last 10 minutes first, then sorts by score
tipsOrBountiesAwarded &&
c.createdTime > Date.now() - 10 * MINUTE_MS &&
c.userId === me?.id
? -Infinity
: -((c.bountiesAwarded ?? 0) + sum(Object.values(tips[c.id] ?? [])))
),
(c) => c.replyToCommentId ?? '_'
)
const topLevelComments = commentsByParent['_'] ?? []
return ( return (
<> <>
<ContractCommentInput className="mb-5" contract={contract} /> <ContractCommentInput className="mb-5" contract={contract} />

View File

@ -16,7 +16,7 @@ export default function LabsPage() {
url="/labs" url="/labs"
/> />
<Col className="px-4"> <Col className="px-4">
<Title className="sm:!mt-0" text="Manifold Labs" /> <Title className="sm:!mt-0" text="🧪 Manifold Labs" />
<Masonry <Masonry
breakpointCols={{ default: 2, 768: 1 }} breakpointCols={{ default: 2, 768: 1 }}