From a1dcf8d1686b601c70f9c37ae8766f4eae210037 Mon Sep 17 00:00:00 2001 From: Ian Philips Date: Mon, 3 Oct 2022 16:38:12 -0600 Subject: [PATCH] Add best sort to FR contracts --- web/components/contract/contract-tabs.tsx | 110 ++++++++++------------ 1 file changed, 50 insertions(+), 60 deletions(-) diff --git a/web/components/contract/contract-tabs.tsx b/web/components/contract/contract-tabs.tsx index c28cb5cb..9639a57a 100644 --- a/web/components/contract/contract-tabs.tsx +++ b/web/components/contract/contract-tabs.tsx @@ -93,24 +93,56 @@ const CommentsTabContent = memo(function CommentsTabContent(props: { 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] ?? []))) - ) + // replied to answers/comments are NOT newest, otherwise newest first + const shouldBeNewestFirst = (c: ContractComment) => + c.replyToCommentId == undefined && + (contract.outcomeType === 'FREE_RESPONSE' + ? c.betId === undefined && c.answerOutcome == undefined + : true) + + // TODO: links to comments are broken because tips load after render and + // comments will reorganize themselves if there are tips/bounties awarded + const sortedComments = sortBy(comments, [ + sort === 'Best' + ? (c) => + // 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 && + shouldBeNewestFirst(c) + ? -Infinity + : -((c.bountiesAwarded ?? 0) + sum(Object.values(tips[c.id] ?? []))) + : (c) => c, + (c) => (!shouldBeNewestFirst(c) ? c.createdTime : -c.createdTime), + ]) 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() + + const sortRow = comments.length > 0 && ( + + + + + + ) if (contract.outcomeType === 'FREE_RESPONSE') { const sortedAnswers = sortBy( @@ -118,14 +150,16 @@ const CommentsTabContent = memo(function CommentsTabContent(props: { (a) => -getOutcomeProbability(contract, a.id) ) const commentsByOutcome = groupBy( - comments, + sortedComments, (c) => c.answerOutcome ?? c.betOutcome ?? '_' ) const generalTopLevelComments = topLevelComments.filter( (c) => c.answerOutcome === undefined && c.betId === undefined ) + return ( <> + {sortRow} {sortedAnswers.map((answer) => (
c.createdTime - )} + answerComments={commentsByOutcome[answer.number.toString()] ?? []} tips={tips} />
@@ -146,6 +177,7 @@ const CommentsTabContent = memo(function CommentsTabContent(props: {
General Comments
+ {sortRow} {generalTopLevelComments.map((comment) => ( ) } else { - // TODO: links to comments are broken because tips load after render and - // comments will reorganize themselves if there are tips/bounties awarded - 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 ( <> + {sortRow} - - {comments.length > 0 && ( - - - - - - )} - {topLevelComments.map((parent) => (