about summary refs log tree commit diff
diff options
context:
space:
mode:
authordan <dan.abramov@gmail.com>2024-02-13 03:53:05 +0000
committerGitHub <noreply@github.com>2024-02-12 19:53:05 -0800
commit588ccde005ae2a4c09568318cc92463468ac8da7 (patch)
treec39bc4662502a2f84094d11eabc1cd24ba8a4a0e
parentbbf049d477817f745b26887612ed68e0ae00daf3 (diff)
downloadvoidsky-588ccde005ae2a4c09568318cc92463468ac8da7.tar.zst
Fix duplicate keys in PostThread (#2854)
-rw-r--r--src/view/com/post-thread/PostThread.tsx27
1 files changed, 15 insertions, 12 deletions
diff --git a/src/view/com/post-thread/PostThread.tsx b/src/view/com/post-thread/PostThread.tsx
index ef3d7e2b6..50e2c69da 100644
--- a/src/view/com/post-thread/PostThread.tsx
+++ b/src/view/com/post-thread/PostThread.tsx
@@ -25,6 +25,8 @@ import {useSetTitle} from 'lib/hooks/useSetTitle'
 import {
   ThreadNode,
   ThreadPost,
+  ThreadNotFound,
+  ThreadBlocked,
   usePostThreadQuery,
   sortThread,
 } from '#/state/queries/post-thread'
@@ -49,18 +51,11 @@ const MAINTAIN_VISIBLE_CONTENT_POSITION = {minIndexForVisible: 1}
 
 const TOP_COMPONENT = {_reactKey: '__top_component__'}
 const REPLY_PROMPT = {_reactKey: '__reply__'}
-const DELETED = {_reactKey: '__deleted__'}
-const BLOCKED = {_reactKey: '__blocked__'}
 const CHILD_SPINNER = {_reactKey: '__child_spinner__'}
 const LOAD_MORE = {_reactKey: '__load_more__'}
 const BOTTOM_COMPONENT = {_reactKey: '__bottom_component__'}
 
-type YieldedItem =
-  | ThreadPost
-  | typeof TOP_COMPONENT
-  | typeof REPLY_PROMPT
-  | typeof DELETED
-  | typeof BLOCKED
+type YieldedItem = ThreadPost | typeof TOP_COMPONENT | typeof REPLY_PROMPT
 
 export function PostThread({
   uri,
@@ -257,7 +252,7 @@ function PostThreadLoaded({
             {!isMobile && <ComposePrompt onPressCompose={onPressReply} />}
           </View>
         )
-      } else if (item === DELETED) {
+      } else if (isThreadNotFound(item)) {
         return (
           <View style={[pal.border, pal.viewLight, styles.itemContainer]}>
             <Text type="lg-bold" style={pal.textLight}>
@@ -265,7 +260,7 @@ function PostThreadLoaded({
             </Text>
           </View>
         )
-      } else if (item === BLOCKED) {
+      } else if (isThreadBlocked(item)) {
         return (
           <View style={[pal.border, pal.viewLight, styles.itemContainer]}>
             <Text type="lg-bold" style={pal.textLight}>
@@ -486,6 +481,14 @@ function isThreadPost(v: unknown): v is ThreadPost {
   return !!v && typeof v === 'object' && 'type' in v && v.type === 'post'
 }
 
+function isThreadNotFound(v: unknown): v is ThreadNotFound {
+  return !!v && typeof v === 'object' && 'type' in v && v.type === 'not-found'
+}
+
+function isThreadBlocked(v: unknown): v is ThreadBlocked {
+  return !!v && typeof v === 'object' && 'type' in v && v.type === 'blocked'
+}
+
 function* flattenThreadSkeleton(
   node: ThreadNode,
   hasSession: boolean,
@@ -518,9 +521,9 @@ function* flattenThreadSkeleton(
       yield CHILD_SPINNER
     }
   } else if (node.type === 'not-found') {
-    yield DELETED
+    yield node
   } else if (node.type === 'blocked') {
-    yield BLOCKED
+    yield node
   }
 }