diff options
author | dan <dan.abramov@gmail.com> | 2023-11-30 21:35:58 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-30 13:35:58 -0800 |
commit | 46b63accb8e73997f2a1bee24cfda220d29e048b (patch) | |
tree | 748de65b464e98d8241cc6fd8d11a9c17d9ec05c /src/state/queries/post-thread.ts | |
parent | 143fc80951d3a0620c0a5e55f46229f2fc743758 (diff) | |
download | voidsky-46b63accb8e73997f2a1bee24cfda220d29e048b.tar.zst |
Rewrite the shadow logic to look inside the cache (#2045)
* Reset * Associate shadows with the cache * Use colocated helpers * Fix types * Reorder for clarity * More types * Copy paste logic for profile * Hook up profile query * Hook up suggested follows * Hook up other profile things * Fix shape * Pass setShadow into the effect deps * Include reply posts in the shadow cache search --------- Co-authored-by: Paul Frazee <pfrazee@gmail.com>
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 { |