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>
This commit is contained in:
dan 2023-11-30 21:35:58 +00:00 committed by GitHub
parent 143fc80951
commit 46b63accb8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 462 additions and 172 deletions

View file

@ -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 {