Checkpoint: handling exhausted replies
This commit is contained in:
@@ -261,15 +261,17 @@ export function usePostThread({anchor}: {anchor?: string}) {
|
|||||||
* of server-hidden replies.
|
* of server-hidden replies.
|
||||||
*/
|
*/
|
||||||
const items = useMemo(() => {
|
const items = useMemo(() => {
|
||||||
|
const result = [...threadItems]
|
||||||
|
|
||||||
if (query.isPlaceholderData) {
|
if (query.isPlaceholderData) {
|
||||||
const anchorPost = threadItems.at(0)
|
const anchorPost = result.at(0)
|
||||||
const skeletonReplies =
|
const skeletonReplies =
|
||||||
anchorPost && anchorPost.type === 'threadPost'
|
anchorPost && anchorPost.type === 'threadPost'
|
||||||
? anchorPost?.value.post.replyCount ?? 4
|
? anchorPost?.value.post.replyCount ?? 4
|
||||||
: 4
|
: 4
|
||||||
|
|
||||||
if (!threadItems.length) {
|
if (!result.length) {
|
||||||
threadItems.push(
|
result.push(
|
||||||
views.skeleton({
|
views.skeleton({
|
||||||
key: anchor!,
|
key: anchor!,
|
||||||
item: 'anchor',
|
item: 'anchor',
|
||||||
@@ -277,7 +279,7 @@ export function usePostThread({anchor}: {anchor?: string}) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
if (hasSession) {
|
if (hasSession) {
|
||||||
threadItems.push(
|
result.push(
|
||||||
views.skeleton({
|
views.skeleton({
|
||||||
key: 'replyComposer',
|
key: 'replyComposer',
|
||||||
item: 'replyComposer',
|
item: 'replyComposer',
|
||||||
@@ -287,7 +289,7 @@ export function usePostThread({anchor}: {anchor?: string}) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (let i = 0; i < skeletonReplies; i++) {
|
for (let i = 0; i < skeletonReplies; i++) {
|
||||||
threadItems.push(
|
result.push(
|
||||||
views.skeleton({
|
views.skeleton({
|
||||||
key: `${anchor!}-reply-${i}`,
|
key: `${anchor!}-reply-${i}`,
|
||||||
item: 'reply',
|
item: 'reply',
|
||||||
@@ -295,9 +297,15 @@ export function usePostThread({anchor}: {anchor?: string}) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return threadItems
|
return result
|
||||||
} else {
|
} else {
|
||||||
return threadItems.concat(additionalHiddenItems)
|
result.push(...additionalHiddenItems)
|
||||||
|
result.push({
|
||||||
|
type: 'bookend',
|
||||||
|
key: 'bookend-down',
|
||||||
|
direction: 'down',
|
||||||
|
})
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
}, [
|
}, [
|
||||||
query.isPlaceholderData,
|
query.isPlaceholderData,
|
||||||
|
|||||||
@@ -382,15 +382,17 @@ export function combine(
|
|||||||
loadServerHiddenItems: () => Promise<void>
|
loadServerHiddenItems: () => Promise<void>
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
for (let i = 0; i < items.length; i++) {
|
const result = [...items]
|
||||||
const item = items[i]
|
|
||||||
|
for (let i = 0; i < result.length; i++) {
|
||||||
|
const item = result[i]
|
||||||
if (
|
if (
|
||||||
item.type === 'threadPost' &&
|
item.type === 'threadPost' &&
|
||||||
item.depth === 0 &&
|
item.depth === 0 &&
|
||||||
!item.value.post.viewer?.replyDisabled &&
|
!item.value.post.viewer?.replyDisabled &&
|
||||||
hasSession
|
hasSession
|
||||||
) {
|
) {
|
||||||
items.splice(i + 1, 0, {
|
result.splice(i + 1, 0, {
|
||||||
type: 'replyComposer',
|
type: 'replyComposer',
|
||||||
key: 'replyComposer',
|
key: 'replyComposer',
|
||||||
})
|
})
|
||||||
@@ -400,9 +402,9 @@ export function combine(
|
|||||||
|
|
||||||
if (hidden.length || hasServerHiddenItems) {
|
if (hidden.length || hasServerHiddenItems) {
|
||||||
if (hiddenItemsVisible) {
|
if (hiddenItemsVisible) {
|
||||||
return items.concat(hidden)
|
result.push(...hidden)
|
||||||
} else {
|
} else {
|
||||||
return items.concat({
|
result.push({
|
||||||
type: 'showHiddenReplies',
|
type: 'showHiddenReplies',
|
||||||
key: 'showHiddenReplies',
|
key: 'showHiddenReplies',
|
||||||
onLoad: loadServerHiddenItems,
|
onLoad: loadServerHiddenItems,
|
||||||
@@ -410,7 +412,7 @@ export function combine(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return items
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -104,6 +104,11 @@ export type ThreadItem =
|
|||||||
key: string
|
key: string
|
||||||
item: 'anchor' | 'reply' | 'replyComposer'
|
item: 'anchor' | 'reply' | 'replyComposer'
|
||||||
}
|
}
|
||||||
|
| {
|
||||||
|
type: 'bookend'
|
||||||
|
key: string
|
||||||
|
direction: 'up' | 'down'
|
||||||
|
}
|
||||||
|
|
||||||
export type TraversalMetadata = {
|
export type TraversalMetadata = {
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user