Almost there with read mores

This commit is contained in:
Eric Bailey
2025-05-27 23:27:59 -05:00
parent 526bfedf82
commit 3247fe1137
4 changed files with 63 additions and 27 deletions
@@ -192,14 +192,18 @@ let PostThreadItemLoaded = ({
t.atoms.border_contrast_low, t.atoms.border_contrast_low,
], ],
]}> ]}>
{Array.from(Array(indents)).map((_, n: number) => ( {Array.from(Array(indents)).map((_, n: number) => {
const isLastIteration = n === indents - 1
return (
<View <View
key={`${post.uri}-padding-${n}`} key={`${post.uri}-padding-${n}`}
style={[ style={[
t.atoms.border_contrast_low, t.atoms.border_contrast_low,
{ {
borderRightWidth: borderRightWidth:
item.ui.isDeadEnd && n === indents - 1 && !item.ui.hasReadMore isLastIteration &&
item.ui.isDeadEnd &&
!item.ui.precedesParentReadMore
? 0 ? 0
: REPLY_LINE_WIDTH, : REPLY_LINE_WIDTH,
width: TREE_INDENT + TREE_AVI_WIDTH / 2, width: TREE_INDENT + TREE_AVI_WIDTH / 2,
@@ -207,7 +211,8 @@ let PostThreadItemLoaded = ({
}, },
]} ]}
/> />
))} )
})}
<View style={a.flex_1}> <View style={a.flex_1}>
<SubtleHover> <SubtleHover>
<View <View
@@ -220,6 +225,9 @@ let PostThreadItemLoaded = ({
!item.ui.showParentReplyLine && a.pt_lg, !item.ui.showParentReplyLine && a.pt_lg,
!item.ui.showChildReplyLine && a.pb_sm, !item.ui.showChildReplyLine && a.pb_sm,
], ],
item.ui.isDeadEnd &&
!item.ui.precedesParentReadMore &&
!item.ui.precedesChildReadMore && [a.pb_sm],
]}> ]}>
{item.ui.indent > 1 && item.ui.parentHasBranchingReplies && ( {item.ui.indent > 1 && item.ui.parentHasBranchingReplies && (
<View <View
+11 -5
View File
@@ -59,12 +59,15 @@ export function flatten(
if (item.depth <= parent.depth) { if (item.depth <= parent.depth) {
/* /*
* Find the previous post item and set the `hasReadMore` flag * Find the previous post item and set the read more flags
*/ */
for (let ui = i - 1; ui >= 0; ui--) { for (let ui = i - 1; ui >= 0; ui--) {
let prev = flattened[ui] let prev = flattened[ui]
if (prev.type === 'threadPost') { if (prev.type === 'threadPost') {
prev.ui.hasReadMore = true prev.ui.precedesParentReadMore =
prev.ui.indent - 1 === parent.ui.indent // true
prev.ui.precedesChildReadMore =
prev.ui.indent === item.ui.indent
break break
} }
} }
@@ -107,12 +110,15 @@ export function flatten(
const parent = parents[pi] const parent = parents[pi]
if (parent.depth <= item.depth) { if (parent.depth <= item.depth) {
/* /*
* Find the previous post item and set the `hasReadMore` flag * Find the previous post item and set the read more flags
*/ */
for (let ui = i; ui >= 0; ui--) { for (let ui = i; ui >= 0; ui--) {
let prev = flattened[ui] let prev = flattened[ui]
if (prev.type === 'threadPost') { if (prev.type === 'threadPost') {
prev.ui.hasReadMore = true prev.ui.precedesParentReadMore =
prev.ui.indent - 1 === parent.ui.indent
prev.ui.precedesChildReadMore =
prev.ui.indent === item.ui.indent
break break
} }
} }
@@ -141,7 +147,7 @@ export function flatten(
} }
} }
} }
// console.log(flattened) console.log(flattened)
/* /*
* Insert hidden items and buttons to show them * Insert hidden items and buttons to show them
+12 -1
View File
@@ -52,7 +52,18 @@ export type Slice =
indent: number indent: number
parentHasBranchingReplies: boolean parentHasBranchingReplies: boolean
isDeadEnd: boolean isDeadEnd: boolean
hasReadMore?: boolean /**
* Populated during the final traversal of the thread. Denotes whether
* there is a "Read more" link for the parent immediately following
* this item.
*/
precedesParentReadMore?: boolean
/**
* Populated during the final traversal of the thread. Denotes whether
* there is a "Read more" link for this item immediately following
* this item.
*/
precedesChildReadMore?: boolean
} }
} }
| { | {
+16 -5
View File
@@ -81,6 +81,15 @@ export function threadPost({
moderationOpts: ModerationOpts moderationOpts: ModerationOpts
traversalMetadata?: TraversalMetadata traversalMetadata?: TraversalMetadata
}): Extract<Slice, {type: 'threadPost'}> { }): Extract<Slice, {type: 'threadPost'}> {
const parentHasBranchingReplies = !!traversalMetadata?.hasBranchingReplies
/*
* Indent differs from depth in cases where the tree has no branches, and so
* we can maintain the more shallow depth of the parent.
*/
const indent = parentHasBranchingReplies
? depth
: traversalMetadata?.indent || depth
return { return {
type: 'threadPost', type: 'threadPost',
key: uri, key: uri,
@@ -101,11 +110,13 @@ export function threadPost({
isAnchor: depth === 0, isAnchor: depth === 0,
showParentReplyLine: !!oneUp && oneUp.depth !== 0 && oneUp.depth < depth, showParentReplyLine: !!oneUp && oneUp.depth !== 0 && oneUp.depth < depth,
showChildReplyLine: (value.post.replyCount || 0) > 0, showChildReplyLine: (value.post.replyCount || 0) > 0,
indent: traversalMetadata?.hasBranchingReplies indent,
? depth parentHasBranchingReplies,
: traversalMetadata?.indent || depth, /*
parentHasBranchingReplies: !!traversalMetadata?.hasBranchingReplies, * If there are no slices below this one, or the next slice is less
isDeadEnd: !oneDown || oneDown?.depth < depth, * indented than the computed indent for this post.
*/
isDeadEnd: !oneDown || oneDown?.depth < indent,
}, },
} }
} }