From 9e9ab550270e9fecc7c5f063d6d8958d2352127c Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Fri, 23 May 2025 09:33:35 -0500 Subject: [PATCH] Fix highlighted post calc --- src/state/queries/usePostThread/index.ts | 2 +- src/state/queries/usePostThread/traversal.ts | 26 ++++++++++++-------- src/state/queries/usePostThread/views.ts | 4 +-- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/state/queries/usePostThread/index.ts b/src/state/queries/usePostThread/index.ts index fff265e2ab..d0a265398c 100644 --- a/src/state/queries/usePostThread/index.ts +++ b/src/state/queries/usePostThread/index.ts @@ -44,7 +44,7 @@ export function usePostThread({ async queryFn() { const {data} = await agent.app.bsky.unspecced.getPostThreadV2({ anchor: uri!, - branchingFactor: params.view === 'linear' ? 1 : 10, + branchingFactor: params.view === 'linear' ? 1 : 100, below: 10, sorting: mapSortOptionsToSortID(params.sort), }) diff --git a/src/state/queries/usePostThread/traversal.ts b/src/state/queries/usePostThread/traversal.ts index d60481278d..4da1935ba1 100644 --- a/src/state/queries/usePostThread/traversal.ts +++ b/src/state/queries/usePostThread/traversal.ts @@ -60,11 +60,21 @@ export function flatten( const item = flattened[i] // TODO should not insert if not found post etc - if (item.type === 'threadPost' && item.depth === 0) { - flattened.splice(i + 1, 0, { - type: 'replyComposer', - key: 'replyComposer', - }) + if (item.type === 'threadPost') { + if (item.ui.isAnchor) { + flattened.splice(i + 1, 0, { + type: 'replyComposer', + key: 'replyComposer', + }) + } + + if ( + item.value.post.replyCount && + item.value.post.replyCount > 0 && + !item.ui.showChildReplyLine + ) { + console.log('insert more link') + } } } } @@ -178,11 +188,7 @@ export function sort( i = branch.end continue traversal } else if (AppBskyUnspeccedGetPostThreadV2.isThreadItemPost(item.value)) { - const lastSlice = items[items.length - 1] - const isFirstReply = - lastSlice.type === 'replyComposer' || - (lastSlice.type === 'threadPost' && lastSlice.depth === 0) - const oneUp = isFirstReply ? undefined : thread.at(i - 1) + const oneUp = thread.at(i - 1) const oneDown = thread.at(i + 1) const post = views.threadPost({ uri: item.uri, diff --git a/src/state/queries/usePostThread/views.ts b/src/state/queries/usePostThread/views.ts index ee1d32d1f4..50c0d27a82 100644 --- a/src/state/queries/usePostThread/views.ts +++ b/src/state/queries/usePostThread/views.ts @@ -94,8 +94,8 @@ export function threadPost({ moderation: moderatePost(value.post, moderationOpts), ui: { isAnchor: depth === 0, - showParentReplyLine: !!oneUp && oneUp.depth < depth, - showChildReplyLine: !!oneDown && oneDown.depth > depth, + showParentReplyLine: !!oneUp && oneUp.depth !== 0 && oneUp.depth < depth, + showChildReplyLine: !!oneDown && depth !== 0 && oneDown.depth > depth, }, } }