From ff61c99a6be8b9aa7a57bb92b983932e56dc309c Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Mon, 9 Jun 2025 14:20:18 -0500 Subject: [PATCH] Update metadata comments, dev mode --- src/state/queries/usePostThread/types.ts | 21 ++++++++++++++++----- src/state/queries/usePostThread/utils.ts | 3 ++- src/storage/hooks/dev-mode.ts | 14 ++++++++++++++ 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/src/state/queries/usePostThread/types.ts b/src/state/queries/usePostThread/types.ts index 785d7a369c..223df7577a 100644 --- a/src/state/queries/usePostThread/types.ts +++ b/src/state/queries/usePostThread/types.ts @@ -93,6 +93,9 @@ export type ThreadItem = onPress: () => void } | { + /* + * Read more replies, downwards in the thread. + */ type: 'readMore' key: string depth: number @@ -101,6 +104,9 @@ export type ThreadItem = skippedIndentIndices: Set } | { + /* + * Read more parents, upwards in the thread. + */ type: 'readMoreUp' key: string href: string @@ -110,12 +116,17 @@ export type ThreadItem = key: string item: 'anchor' | 'reply' | 'replyComposer' } - | { - type: 'bookend' - key: string - direction: 'up' | 'down' - } +/** + * Metadata collected while traversing the raw data from the thread response. + * Some values here can be computed immediately, while others need to be + * computed during a second pass over the thread after we know things like + * totaly number of replies, the reply index, etc. + * + * The idea here is that these values should be objectively true in all cases, + * such that we can use them later — either individually on in composite — to + * drive rendering behaviors. + */ export type TraversalMetadata = { /** * The depth of the post in the reply tree, where 0 is the root post. This is diff --git a/src/state/queries/usePostThread/utils.ts b/src/state/queries/usePostThread/utils.ts index 2c597075b6..d3818f2389 100644 --- a/src/state/queries/usePostThread/utils.ts +++ b/src/state/queries/usePostThread/utils.ts @@ -12,6 +12,7 @@ import { type ThreadItem, type TraversalMetadata, } from '#/state/queries/usePostThread/types' +import {isDevMode} from '#/storage/hooks/dev-mode' import * as bsky from '#/types/bsky' export function getThreadgateRecord( @@ -111,7 +112,7 @@ export function storeTraversalMetadata( ) { metadatas.set(metadata.postData.uri, metadata) - if (__DEV__) { + if (isDevMode()) { // @ts-ignore dev only for debugging metadatas.set(metadata.postData.text, metadata) // @ts-ignore diff --git a/src/storage/hooks/dev-mode.ts b/src/storage/hooks/dev-mode.ts index 49eca3bb11..331825c48f 100644 --- a/src/storage/hooks/dev-mode.ts +++ b/src/storage/hooks/dev-mode.ts @@ -5,3 +5,17 @@ export function useDevMode() { return [devMode, setDevMode] as const } + +let cachedIsDevMode: boolean | undefined +/** + * Does not update when toggling dev mode on or off. This util simply retrieves + * the value and caches in memory indefinitely. So after an update, you'll need + * to reload the app so it can pull a fresh value from storage. + */ +export function isDevMode() { + if (__DEV__) return true + if (cachedIsDevMode === undefined) { + cachedIsDevMode = device.get(['devMode']) ?? false + } + return cachedIsDevMode +}