From 2e3f1b4c52127b96136c383ca405eb5cc437cd1a Mon Sep 17 00:00:00 2001 From: Austin Chen Date: Sat, 22 Jan 2022 11:46:59 -0600 Subject: [PATCH] Collapse long threads on the activity feed --- web/components/contract-feed.tsx | 59 +++++++++++++++++++++++++++++--- 1 file changed, 54 insertions(+), 5 deletions(-) diff --git a/web/components/contract-feed.tsx b/web/components/contract-feed.tsx index 07d2e578..276f5f7b 100644 --- a/web/components/contract-feed.tsx +++ b/web/components/contract-feed.tsx @@ -5,6 +5,7 @@ import { BanIcon, ChatAltIcon, CheckIcon, + DotsVerticalIcon, LockClosedIcon, StarIcon, UserIcon, @@ -235,8 +236,9 @@ function TruncatedComment(props: { let truncated = comment // Keep descriptions to at most 400 characters - if (shouldTruncate && truncated.length > 400) { - truncated = truncated.slice(0, 400) + const MAX_CHARS = 400 + if (shouldTruncate && truncated.length > MAX_CHARS) { + truncated = truncated.slice(0, MAX_CHARS) // Make sure to end on a space const i = truncated.lastIndexOf(' ') truncated = truncated.slice(0, i) @@ -561,11 +563,45 @@ function FeedBetGroup(props: { activityItem: any }) { ) } +// TODO: Should highlight the entire Feed segment +function FeedExpand(props: { setExpanded: (expanded: boolean) => void }) { + const { setExpanded } = props + return ( + <> + + + + + ) +} + // Missing feed items: // - Bet sold? type ActivityItem = { id: string - type: 'bet' | 'comment' | 'start' | 'betgroup' | 'close' | 'resolve' + type: + | 'bet' + | 'comment' + | 'start' + | 'betgroup' + | 'close' + | 'resolve' + | 'expand' } export function ContractFeed(props: { @@ -577,6 +613,7 @@ export function ContractFeed(props: { }) { const { contract, feedType } = props const { id } = contract + const [expanded, setExpanded] = useState(false) const user = useUser() let bets = useBets(id) ?? props.bets @@ -597,13 +634,23 @@ export function ContractFeed(props: { allItems.push({ type: 'resolve', id: `${contract.resolutionTime}` }) } + // If there are more than 5 items, only show the first, an expand item, and last 3 + let items = allItems + if (!expanded && allItems.length > 5 && feedType == 'activity') { + items = [ + allItems[0], + { type: 'expand', id: 'expand' }, + ...allItems.slice(-3), + ] + } + return (