Use indent ya idiot

This commit is contained in:
Eric Bailey
2025-05-27 21:24:02 -05:00
parent e939e41450
commit fd0162c321
5 changed files with 36 additions and 24 deletions
@@ -179,7 +179,11 @@ let PostThreadItemLoaded = ({
<View
style={[
a.flex_row,
item.ui.indent === 1 && [a.border_t, t.atoms.border_contrast_low],
item.ui.indent === 1 &&
!item.ui.showParentReplyLine && [
a.border_t,
t.atoms.border_contrast_low,
],
]}>
{Array.from(Array(item.ui.indent - 1)).map((_, n: number) => (
<View
@@ -196,7 +200,15 @@ let PostThreadItemLoaded = ({
))}
<View style={a.flex_1}>
<SubtleHover>
<View style={[a.px_lg, a.pt_sm, item.ui.indent === 1 && [a.pt_lg]]}>
<View
style={[
a.px_lg,
a.pt_sm,
item.ui.indent === 1 && [
!item.ui.showParentReplyLine && a.pt_lg,
!item.ui.showChildReplyLine && a.pb_sm,
],
]}>
<PostHider
testID={`postThreadItem-by-${post.author.handle}`}
href={postHref}
+13 -16
View File
@@ -118,6 +118,7 @@ export function flatten(
}
}
}
console.log(flattened)
/*
* Insert hidden items and buttons to show them
@@ -199,18 +200,16 @@ export function sort(
) {
items.push(views.threadPostBlocked(item))
} else if (AppBskyUnspeccedGetPostThreadV2.isThreadItemPost(item.value)) {
postDataMap.set(item.uri, getPostTraversalMetadata(item))
items.push(
views.threadPost({
uri: item.uri,
depth: item.depth,
value: item.value,
oneUp: thread[i - 1],
oneDown: thread[i + 1],
moderationOpts,
}),
)
const post = views.threadPost({
uri: item.uri,
depth: item.depth,
value: item.value,
oneUp: thread[i - 1],
oneDown: thread[i + 1],
moderationOpts,
})
postDataMap.set(item.uri, getPostTraversalMetadata(post))
items.push(post)
parentTraversal: for (let pi = i - 1; pi >= 0; pi--) {
const parentOneDown = thread[pi + 1]
@@ -269,8 +268,6 @@ export function sort(
i = branch.end
continue traversal
} else if (AppBskyUnspeccedGetPostThreadV2.isThreadItemPost(item.value)) {
postDataMap.set(item.uri, getPostTraversalMetadata(item))
const oneUp = thread.at(i - 1)
const oneDown = thread.at(i + 1)
const post = views.threadPost({
@@ -284,6 +281,7 @@ export function sort(
oneDown,
moderationOpts,
})
postDataMap.set(item.uri, getPostTraversalMetadata(post))
const postMod = getModerationState(post.moderation)
const postIsHiddenByThreadgate = threadgateHiddenReplies.has(item.uri)
const postIsModerated =
@@ -318,8 +316,6 @@ export function sort(
if (
AppBskyUnspeccedGetPostThreadV2.isThreadItemPost(child.value)
) {
postDataMap.set(child.uri, getPostTraversalMetadata(child))
const childPost = views.threadPost({
uri: child.uri,
depth: child.depth,
@@ -331,6 +327,7 @@ export function sort(
oneDown: thread[ci + 1],
moderationOpts,
})
postDataMap.set(child.uri, getPostTraversalMetadata(childPost))
const childPostMod = getModerationState(childPost.moderation)
const childPostIsHiddenByThreadgate =
threadgateHiddenReplies.has(child.uri)
+1 -1
View File
@@ -93,6 +93,6 @@ export type Slice =
}
export type TraversalMetadata = {
depth: number
indent: number
hasBranchingReplies: boolean
}
+6 -3
View File
@@ -6,7 +6,10 @@ import {
AtUri,
} from '@atproto/api'
import {type TraversalMetadata} from '#/state/queries/usePostThread/types'
import {
type Slice,
type TraversalMetadata,
} from '#/state/queries/usePostThread/types'
import * as bsky from '#/types/bsky'
export function getThreadgateRecord(
@@ -38,13 +41,13 @@ export function getPostRecord(post: AppBskyFeedDefs.PostView) {
}
export function getPostTraversalMetadata(
item: AppBskyUnspeccedGetPostThreadV2.ThreadItem,
item: Extract<Slice, {type: 'threadPost'}>,
): TraversalMetadata | undefined {
if (!AppBskyUnspeccedGetPostThreadV2.isThreadItemPost(item.value)) return
const replyCount = item.value.post.replyCount || 0
const unhydratedReplies = item.value.moreReplies || 0
return {
depth: item.depth,
indent: item.ui.indent,
/**
* If the post has more than a single reply, and the total reply count
* minus the number of replies not present in the response is greater than
+2 -2
View File
@@ -102,7 +102,7 @@ export function threadPost({
showChildReplyLine: (value.post.replyCount || 0) > 0,
indent: traversalMetadata?.hasBranchingReplies
? depth
: traversalMetadata?.depth || depth,
: traversalMetadata?.indent || depth,
parentHasBranchingReplies: !!traversalMetadata?.hasBranchingReplies,
},
}
@@ -118,7 +118,7 @@ export function readMore({
key: `readMore:${parent.uri}`,
indent: parent.ui.parentHasBranchingReplies
? parent.depth
: Math.max(0, parent.depth - 1),
: parent.ui.indent,
replyCount: parent.value.moreReplies,
nextAnchor: parent,
nextAnchorUri: new AtUri(parent.uri),