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,22 +192,27 @@ let PostThreadItemLoaded = ({
t.atoms.border_contrast_low,
],
]}>
{Array.from(Array(indents)).map((_, n: number) => (
<View
key={`${post.uri}-padding-${n}`}
style={[
t.atoms.border_contrast_low,
{
borderRightWidth:
item.ui.isDeadEnd && n === indents - 1 && !item.ui.hasReadMore
? 0
: REPLY_LINE_WIDTH,
width: TREE_INDENT + TREE_AVI_WIDTH / 2,
left: 1,
},
]}
/>
))}
{Array.from(Array(indents)).map((_, n: number) => {
const isLastIteration = n === indents - 1
return (
<View
key={`${post.uri}-padding-${n}`}
style={[
t.atoms.border_contrast_low,
{
borderRightWidth:
isLastIteration &&
item.ui.isDeadEnd &&
!item.ui.precedesParentReadMore
? 0
: REPLY_LINE_WIDTH,
width: TREE_INDENT + TREE_AVI_WIDTH / 2,
left: 1,
},
]}
/>
)
})}
<View style={a.flex_1}>
<SubtleHover>
<View
@@ -220,6 +225,9 @@ let PostThreadItemLoaded = ({
!item.ui.showParentReplyLine && a.pt_lg,
!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 && (
<View
+11 -5
View File
@@ -59,12 +59,15 @@ export function flatten(
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--) {
let prev = flattened[ui]
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
}
}
@@ -107,12 +110,15 @@ export function flatten(
const parent = parents[pi]
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--) {
let prev = flattened[ui]
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
}
}
@@ -141,7 +147,7 @@ export function flatten(
}
}
}
// console.log(flattened)
console.log(flattened)
/*
* Insert hidden items and buttons to show them
+12 -1
View File
@@ -52,7 +52,18 @@ export type Slice =
indent: number
parentHasBranchingReplies: 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
traversalMetadata?: TraversalMetadata
}): 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 {
type: 'threadPost',
key: uri,
@@ -101,11 +110,13 @@ export function threadPost({
isAnchor: depth === 0,
showParentReplyLine: !!oneUp && oneUp.depth !== 0 && oneUp.depth < depth,
showChildReplyLine: (value.post.replyCount || 0) > 0,
indent: traversalMetadata?.hasBranchingReplies
? depth
: traversalMetadata?.indent || depth,
parentHasBranchingReplies: !!traversalMetadata?.hasBranchingReplies,
isDeadEnd: !oneDown || oneDown?.depth < depth,
indent,
parentHasBranchingReplies,
/*
* If there are no slices below this one, or the next slice is less
* indented than the computed indent for this post.
*/
isDeadEnd: !oneDown || oneDown?.depth < indent,
},
}
}