skeleton view

This commit is contained in:
Eric Bailey
2025-06-04 11:18:01 -05:00
parent b7e5e10ea7
commit a115b6780f
2 changed files with 39 additions and 20 deletions
+25 -20
View File
@@ -15,6 +15,7 @@ import {
type ThreadItem,
} from '#/state/queries/usePostThread/types'
import {getThreadgateRecord} from '#/state/queries/usePostThread/utils'
import * as views from '#/state/queries/usePostThread/views'
import {useAgent, useSession} from '#/state/session'
import {useMergeThreadgateHiddenReplies} from '#/state/threadgate-hidden-replies'
@@ -124,11 +125,12 @@ export function usePostThread({anchor}: {anchor?: string}) {
if (!hasServerHiddenReplies) return
setAdditionalHiddenItems(
Array.from({length: 2}).map((_, i) => ({
type: 'skeleton',
key: `${anchor!}-reply-${i}`,
item: 'reply',
})),
Array.from({length: 2}).map((_, i) =>
views.skeleton({
key: `${anchor!}-reply-${i}`,
item: 'reply',
}),
),
)
const params = {
@@ -212,27 +214,30 @@ export function usePostThread({anchor}: {anchor?: string}) {
: 4
if (!items.length) {
items.push({
type: 'skeleton',
key: anchor!,
item: 'anchor',
})
items.push(
views.skeleton({
key: anchor!,
item: 'anchor',
}),
)
if (hasSession) {
items.push({
type: 'skeleton',
key: 'replyComposer',
item: 'replyComposer',
})
items.push(
views.skeleton({
key: 'replyComposer',
item: 'replyComposer',
}),
)
}
}
for (let i = 0; i < skeletonReplies; i++) {
items.push({
type: 'skeleton',
key: `${anchor!}-reply-${i}`,
item: 'reply',
})
items.push(
views.skeleton({
key: `${anchor!}-reply-${i}`,
item: 'reply',
}),
)
}
}
+14
View File
@@ -115,6 +115,20 @@ export function readMore({
}
}
export function skeleton({
key,
item,
}: Omit<Extract<ThreadItem, {type: 'skeleton'}>, 'type'>): Extract<
ThreadItem,
{type: 'skeleton'}
> {
return {
type: 'skeleton',
key,
item,
}
}
export function postViewToThreadPlaceholder(
post: AppBskyFeedDefs.PostView,
): $Typed<