Fix: only apply self-thread load-more behavior on the outer edge of the reply tree (#4559)

zio/stable
Paul Frazee 2024-06-18 11:48:49 -07:00 committed by GitHub
parent 5f5d845053
commit fb76265fcc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 11 additions and 2 deletions

View File

@ -31,6 +31,7 @@ import {
getEmbeddedPost, getEmbeddedPost,
} from './util' } from './util'
const REPLY_TREE_DEPTH = 10
const RQKEY_ROOT = 'post-thread' const RQKEY_ROOT = 'post-thread'
export const RQKEY = (uri: string) => [RQKEY_ROOT, uri] export const RQKEY = (uri: string) => [RQKEY_ROOT, uri]
type ThreadViewNode = AppBskyFeedGetPostThread.OutputSchema['thread'] type ThreadViewNode = AppBskyFeedGetPostThread.OutputSchema['thread']
@ -90,7 +91,10 @@ export function usePostThreadQuery(uri: string | undefined) {
gcTime: 0, gcTime: 0,
queryKey: RQKEY(uri || ''), queryKey: RQKEY(uri || ''),
async queryFn() { async queryFn() {
const res = await agent.getPostThread({uri: uri!, depth: 10}) const res = await agent.getPostThread({
uri: uri!,
depth: REPLY_TREE_DEPTH,
})
if (res.success) { if (res.success) {
const thread = responseToThreadNodes(res.data.thread) const thread = responseToThreadNodes(res.data.thread)
annotateSelfThread(thread) annotateSelfThread(thread)
@ -287,7 +291,12 @@ function annotateSelfThread(thread: ThreadNode) {
selfThreadNode.ctx.isSelfThread = true selfThreadNode.ctx.isSelfThread = true
} }
const last = selfThreadNodes[selfThreadNodes.length - 1] const last = selfThreadNodes[selfThreadNodes.length - 1]
if (last && last.post.replyCount && !last.replies?.length) { if (
last &&
last.ctx.depth === REPLY_TREE_DEPTH && // at the edge of the tree depth
last.post.replyCount && // has replies
!last.replies?.length // replies were not hydrated
) {
last.ctx.hasMoreSelfThread = true last.ctx.hasMoreSelfThread = true
} }
} }