Optimistic hidden replies (#4977)

This commit is contained in:
Eric Bailey
2024-08-23 14:35:48 -05:00
committed by GitHub
parent 5ec8761b29
commit 425dd5f27f
9 changed files with 70 additions and 129 deletions
+12 -4
View File
@@ -88,7 +88,10 @@ export type ThreadModerationCache = WeakMap<ThreadNode, ModerationDecision>
export function usePostThreadQuery(uri: string | undefined) {
const queryClient = useQueryClient()
const agent = useAgent()
return useQuery<ThreadNode, Error>({
return useQuery<
{thread: ThreadNode; threadgate?: AppBskyFeedDefs.ThreadgateView},
Error
>({
gcTime: 0,
queryKey: RQKEY(uri || ''),
async queryFn() {
@@ -99,16 +102,21 @@ export function usePostThreadQuery(uri: string | undefined) {
if (res.success) {
const thread = responseToThreadNodes(res.data.thread)
annotateSelfThread(thread)
return thread
return {
thread,
threadgate: res.data.threadgate as
| AppBskyFeedDefs.ThreadgateView
| undefined,
}
}
return {type: 'unknown', uri: uri!}
return {thread: {type: 'unknown', uri: uri!}}
},
enabled: !!uri,
placeholderData: () => {
if (!uri) return
const post = findPostInQueryData(queryClient, uri)
if (post) {
return post
return {thread: post}
}
return undefined
},