Add special util
This commit is contained in:
Vendored
+9
-1
@@ -30,11 +30,19 @@ export interface PostShadow {
|
||||
export const POST_TOMBSTONE = Symbol('PostTombstone')
|
||||
|
||||
const emitter = new EventEmitter()
|
||||
export const shadows: WeakMap<
|
||||
const shadows: WeakMap<
|
||||
AppBskyFeedDefs.PostView,
|
||||
Partial<PostShadow>
|
||||
> = new WeakMap()
|
||||
|
||||
/**
|
||||
* Use with caution! This function returns the raw shadow data for a post.
|
||||
* Prefer using `usePostShadow`.
|
||||
*/
|
||||
export function dangerousGetPostShadow(post: AppBskyFeedDefs.PostView) {
|
||||
return shadows.get(post)
|
||||
}
|
||||
|
||||
export function usePostShadow(
|
||||
post: AppBskyFeedDefs.PostView,
|
||||
): Shadow<AppBskyFeedDefs.PostView> | typeof POST_TOMBSTONE {
|
||||
|
||||
@@ -9,7 +9,10 @@ import {
|
||||
} from '@atproto/api'
|
||||
import {type QueryClient} from '@tanstack/react-query'
|
||||
|
||||
import {shadows, updatePostShadow} from '#/state/cache/post-shadow'
|
||||
import {
|
||||
dangerousGetPostShadow,
|
||||
updatePostShadow,
|
||||
} from '#/state/cache/post-shadow'
|
||||
import {findAllPostsInQueryData as findAllPostsInExploreFeedPreviewsQueryData} from '#/state/queries/explore-feed-previews'
|
||||
import {findAllPostsInQueryData as findAllPostsInNotifsQueryData} from '#/state/queries/notifications/feed'
|
||||
import {findAllPostsInQueryData as findAllPostsInFeedQueryData} from '#/state/queries/post-feed'
|
||||
@@ -86,7 +89,7 @@ export function createCacheMutator({
|
||||
/*
|
||||
* Update parent data
|
||||
*/
|
||||
const shadow = shadows.get(parent.value.post)
|
||||
const shadow = dangerousGetPostShadow(parent.value.post)
|
||||
const prevOptimisticCount = shadow?.optimisticReplyCount || 0
|
||||
const prevReplyCount = parent.value.post.replyCount || 0
|
||||
updatePostShadow(queryClient, parent.value.post.uri, {
|
||||
|
||||
Reference in New Issue
Block a user