diff options
Diffstat (limited to 'src/state/queries/post-thread.ts')
-rw-r--r-- | src/state/queries/post-thread.ts | 42 |
1 files changed, 15 insertions, 27 deletions
diff --git a/src/state/queries/post-thread.ts b/src/state/queries/post-thread.ts index d40af1fe2..cde45723a 100644 --- a/src/state/queries/post-thread.ts +++ b/src/state/queries/post-thread.ts @@ -88,7 +88,7 @@ export function usePostThreadQuery(uri: string | undefined) { { const item = findPostInFeedQueryData(queryClient, uri) if (item) { - return feedViewPostToPlaceholderThread(item) + return postViewToPlaceholderThread(item) } } { @@ -213,6 +213,19 @@ function findPostInQueryData( queryClient: QueryClient, uri: string, ): ThreadNode | undefined { + const generator = findAllPostsInQueryData(queryClient, uri) + const result = generator.next() + if (result.done) { + return undefined + } else { + return result.value + } +} + +export function* findAllPostsInQueryData( + queryClient: QueryClient, + uri: string, +): Generator<ThreadNode, void> { const queryDatas = queryClient.getQueriesData<ThreadNode>({ queryKey: ['post-thread'], }) @@ -222,11 +235,10 @@ function findPostInQueryData( } for (const item of traverseThread(queryData)) { if (item.uri === uri) { - return item + yield item } } } - return undefined } function* traverseThread(node: ThreadNode): Generator<ThreadNode, void> { @@ -270,30 +282,6 @@ function threadNodeToPlaceholderThread( } } -function feedViewPostToPlaceholderThread( - item: AppBskyFeedDefs.FeedViewPost, -): ThreadNode { - return { - type: 'post', - _reactKey: item.post.uri, - uri: item.post.uri, - post: item.post, - record: item.post.record as AppBskyFeedPost.Record, // validated in post-feed - parent: undefined, - replies: undefined, - viewer: item.post.viewer, - ctx: { - depth: 0, - isHighlightedPost: true, - hasMore: false, - showChildReplyLine: false, - showParentReplyLine: false, - isParentLoading: !!(item.post.record as AppBskyFeedPost.Record).reply, - isChildLoading: !!item.post.replyCount, - }, - } -} - function postViewToPlaceholderThread( post: AppBskyFeedDefs.PostView, ): ThreadNode { |