From cea5b5a81bd4f9d08851daa811356b3a01caaff4 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Thu, 17 Jul 2025 11:39:22 -0500 Subject: [PATCH] Rename variables for clarity --- src/state/queries/usePostThread/queryCache.ts | 48 +++++++++---------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/state/queries/usePostThread/queryCache.ts b/src/state/queries/usePostThread/queryCache.ts index 74ee13ff80..826932349d 100644 --- a/src/state/queries/usePostThread/queryCache.ts +++ b/src/state/queries/usePostThread/queryCache.ts @@ -77,56 +77,56 @@ export function createCacheMutator({ function mutator(thread: ApiThreadItem[]): T[] { for (let i = 0; i < thread.length; i++) { - const existingParent = thread[i] - if (!AppBskyUnspeccedDefs.isThreadItemPost(existingParent.value)) - continue - if (existingParent.uri !== parentUri) continue + const parent = thread[i] + + if (!AppBskyUnspeccedDefs.isThreadItemPost(parent.value)) continue + if (parent.uri !== parentUri) continue /* * Update parent data */ - existingParent.value.post = { - ...existingParent.value.post, - replyCount: (existingParent.value.post.replyCount || 0) + 1, + parent.value.post = { + ...parent.value.post, + replyCount: (parent.value.post.replyCount || 0) + 1, } - const opDid = getRootPostAtUri(existingParent.value.post)?.host - const nextItem = thread.at(i + 1) - const isReplyToRoot = existingParent.depth === 0 - const isReplyBelowRoot = existingParent.depth > 0 + const opDid = getRootPostAtUri(parent.value.post)?.host + const nextPreexistingItem = thread.at(i + 1) const isEndOfReplyChain = - !nextItem || nextItem.depth <= existingParent.depth - const firstReply = replies.at(0) + !nextPreexistingItem || nextPreexistingItem.depth <= parent.depth + const isParentRoot = parent.depth === 0 + const isParentBelowRoot = parent.depth > 0 + const optimisticReply = replies.at(0) const opIsReplier = AppBskyUnspeccedDefs.isThreadItemPost( - firstReply?.value, + optimisticReply?.value, ) - ? opDid === firstReply.value.post.author.did + ? opDid === optimisticReply.value.post.author.did : false /* * Always insert replies if the following conditions are met. Max * depth checks are handled below. */ - const shouldAlwaysInsertReplies = - isReplyToRoot || - (params.view === 'tree' && isReplyBelowRoot) || + const canAlwaysInsertReplies = + isParentRoot || + (params.view === 'tree' && isParentBelowRoot) || (params.view === 'linear' && isEndOfReplyChain) /* - * Maybe insert replies if the replier is the OP and certain - * conditions are met + * Maybe insert replies if we're in linear view, the replier is the + * OP, and certain conditions are met */ const shouldReplaceWithOPReplies = - params.view === 'linear' && opIsReplier && isReplyBelowRoot + params.view === 'linear' && opIsReplier && isParentBelowRoot - if (shouldAlwaysInsertReplies || shouldReplaceWithOPReplies) { - const branch = getBranch(thread, i, existingParent.depth) + if (canAlwaysInsertReplies || shouldReplaceWithOPReplies) { + const branch = getBranch(thread, i, parent.depth) /* * OP insertions replace other replies _in linear view_. */ const itemsToRemove = shouldReplaceWithOPReplies ? branch.length : 0 const itemsToInsert = replies .map((r, ri) => { - r.depth = existingParent.depth + 1 + ri + r.depth = parent.depth + 1 + ri return r }) .filter(r => {