Fix duplicate keys in PostThread (#2854)
parent
bbf049d477
commit
588ccde005
|
@ -25,6 +25,8 @@ import {useSetTitle} from 'lib/hooks/useSetTitle'
|
||||||
import {
|
import {
|
||||||
ThreadNode,
|
ThreadNode,
|
||||||
ThreadPost,
|
ThreadPost,
|
||||||
|
ThreadNotFound,
|
||||||
|
ThreadBlocked,
|
||||||
usePostThreadQuery,
|
usePostThreadQuery,
|
||||||
sortThread,
|
sortThread,
|
||||||
} from '#/state/queries/post-thread'
|
} from '#/state/queries/post-thread'
|
||||||
|
@ -49,18 +51,11 @@ const MAINTAIN_VISIBLE_CONTENT_POSITION = {minIndexForVisible: 1}
|
||||||
|
|
||||||
const TOP_COMPONENT = {_reactKey: '__top_component__'}
|
const TOP_COMPONENT = {_reactKey: '__top_component__'}
|
||||||
const REPLY_PROMPT = {_reactKey: '__reply__'}
|
const REPLY_PROMPT = {_reactKey: '__reply__'}
|
||||||
const DELETED = {_reactKey: '__deleted__'}
|
|
||||||
const BLOCKED = {_reactKey: '__blocked__'}
|
|
||||||
const CHILD_SPINNER = {_reactKey: '__child_spinner__'}
|
const CHILD_SPINNER = {_reactKey: '__child_spinner__'}
|
||||||
const LOAD_MORE = {_reactKey: '__load_more__'}
|
const LOAD_MORE = {_reactKey: '__load_more__'}
|
||||||
const BOTTOM_COMPONENT = {_reactKey: '__bottom_component__'}
|
const BOTTOM_COMPONENT = {_reactKey: '__bottom_component__'}
|
||||||
|
|
||||||
type YieldedItem =
|
type YieldedItem = ThreadPost | typeof TOP_COMPONENT | typeof REPLY_PROMPT
|
||||||
| ThreadPost
|
|
||||||
| typeof TOP_COMPONENT
|
|
||||||
| typeof REPLY_PROMPT
|
|
||||||
| typeof DELETED
|
|
||||||
| typeof BLOCKED
|
|
||||||
|
|
||||||
export function PostThread({
|
export function PostThread({
|
||||||
uri,
|
uri,
|
||||||
|
@ -257,7 +252,7 @@ function PostThreadLoaded({
|
||||||
{!isMobile && <ComposePrompt onPressCompose={onPressReply} />}
|
{!isMobile && <ComposePrompt onPressCompose={onPressReply} />}
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
} else if (item === DELETED) {
|
} else if (isThreadNotFound(item)) {
|
||||||
return (
|
return (
|
||||||
<View style={[pal.border, pal.viewLight, styles.itemContainer]}>
|
<View style={[pal.border, pal.viewLight, styles.itemContainer]}>
|
||||||
<Text type="lg-bold" style={pal.textLight}>
|
<Text type="lg-bold" style={pal.textLight}>
|
||||||
|
@ -265,7 +260,7 @@ function PostThreadLoaded({
|
||||||
</Text>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
)
|
)
|
||||||
} else if (item === BLOCKED) {
|
} else if (isThreadBlocked(item)) {
|
||||||
return (
|
return (
|
||||||
<View style={[pal.border, pal.viewLight, styles.itemContainer]}>
|
<View style={[pal.border, pal.viewLight, styles.itemContainer]}>
|
||||||
<Text type="lg-bold" style={pal.textLight}>
|
<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'
|
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(
|
function* flattenThreadSkeleton(
|
||||||
node: ThreadNode,
|
node: ThreadNode,
|
||||||
hasSession: boolean,
|
hasSession: boolean,
|
||||||
|
@ -518,9 +521,9 @@ function* flattenThreadSkeleton(
|
||||||
yield CHILD_SPINNER
|
yield CHILD_SPINNER
|
||||||
}
|
}
|
||||||
} else if (node.type === 'not-found') {
|
} else if (node.type === 'not-found') {
|
||||||
yield DELETED
|
yield node
|
||||||
} else if (node.type === 'blocked') {
|
} else if (node.type === 'blocked') {
|
||||||
yield BLOCKED
|
yield node
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue