Thread queryClient explicitly through (#3328)
* Pass queryClient explicitly to resetProfilePostsQueries * Pass queryClient explicitly to updatePostShadow * Pass queryClient explicitly to updateProfileShadow
This commit is contained in:
parent
73df7e53b3
commit
fc1e30afd6
6 changed files with 133 additions and 109 deletions
18
src/state/cache/post-shadow.ts
vendored
18
src/state/cache/post-shadow.ts
vendored
|
@ -1,13 +1,14 @@
|
|||
import {useEffect, useState, useMemo} from 'react'
|
||||
import EventEmitter from 'eventemitter3'
|
||||
import {useEffect, useMemo, useState} from 'react'
|
||||
import {AppBskyFeedDefs} from '@atproto/api'
|
||||
import {QueryClient} from '@tanstack/react-query'
|
||||
import EventEmitter from 'eventemitter3'
|
||||
|
||||
import {batchedUpdates} from '#/lib/batchedUpdates'
|
||||
import {Shadow, castAsShadow} from './types'
|
||||
import {findAllPostsInQueryData as findAllPostsInNotifsQueryData} from '../queries/notifications/feed'
|
||||
import {findAllPostsInQueryData as findAllPostsInFeedQueryData} from '../queries/post-feed'
|
||||
import {findAllPostsInQueryData as findAllPostsInThreadQueryData} from '../queries/post-thread'
|
||||
import {findAllPostsInQueryData as findAllPostsInSearchQueryData} from '../queries/search-posts'
|
||||
import {queryClient} from 'lib/react-query'
|
||||
import {castAsShadow, Shadow} from './types'
|
||||
export type {Shadow} from './types'
|
||||
|
||||
export interface PostShadow {
|
||||
|
@ -93,8 +94,12 @@ function mergeShadow(
|
|||
})
|
||||
}
|
||||
|
||||
export function updatePostShadow(uri: string, value: Partial<PostShadow>) {
|
||||
const cachedPosts = findPostsInCache(uri)
|
||||
export function updatePostShadow(
|
||||
queryClient: QueryClient,
|
||||
uri: string,
|
||||
value: Partial<PostShadow>,
|
||||
) {
|
||||
const cachedPosts = findPostsInCache(queryClient, uri)
|
||||
for (let post of cachedPosts) {
|
||||
shadows.set(post, {...shadows.get(post), ...value})
|
||||
}
|
||||
|
@ -104,6 +109,7 @@ export function updatePostShadow(uri: string, value: Partial<PostShadow>) {
|
|||
}
|
||||
|
||||
function* findPostsInCache(
|
||||
queryClient: QueryClient,
|
||||
uri: string,
|
||||
): Generator<AppBskyFeedDefs.PostView, void> {
|
||||
for (let post of findAllPostsInFeedQueryData(queryClient, uri)) {
|
||||
|
|
15
src/state/cache/profile-shadow.ts
vendored
15
src/state/cache/profile-shadow.ts
vendored
|
@ -1,7 +1,10 @@
|
|||
import {useEffect, useState, useMemo} from 'react'
|
||||
import EventEmitter from 'eventemitter3'
|
||||
import {useEffect, useMemo, useState} from 'react'
|
||||
import {AppBskyActorDefs} from '@atproto/api'
|
||||
import {QueryClient} from '@tanstack/react-query'
|
||||
import EventEmitter from 'eventemitter3'
|
||||
|
||||
import {batchedUpdates} from '#/lib/batchedUpdates'
|
||||
import {findAllProfilesInQueryData as findAllProfilesInActorSearchQueryData} from '../queries/actor-search'
|
||||
import {findAllProfilesInQueryData as findAllProfilesInListMembersQueryData} from '../queries/list-members'
|
||||
import {findAllProfilesInQueryData as findAllProfilesInMyBlockedAccountsQueryData} from '../queries/my-blocked-accounts'
|
||||
import {findAllProfilesInQueryData as findAllProfilesInMyMutedAccountsQueryData} from '../queries/my-muted-accounts'
|
||||
|
@ -11,9 +14,7 @@ import {findAllProfilesInQueryData as findAllProfilesInProfileQueryData} from '.
|
|||
import {findAllProfilesInQueryData as findAllProfilesInProfileFollowersQueryData} from '../queries/profile-followers'
|
||||
import {findAllProfilesInQueryData as findAllProfilesInProfileFollowsQueryData} from '../queries/profile-follows'
|
||||
import {findAllProfilesInQueryData as findAllProfilesInSuggestedFollowsQueryData} from '../queries/suggested-follows'
|
||||
import {findAllProfilesInQueryData as findAllProfilesInActorSearchQueryData} from '../queries/actor-search'
|
||||
import {Shadow, castAsShadow} from './types'
|
||||
import {queryClient} from 'lib/react-query'
|
||||
import {castAsShadow, Shadow} from './types'
|
||||
export type {Shadow} from './types'
|
||||
|
||||
export interface ProfileShadow {
|
||||
|
@ -58,10 +59,11 @@ export function useProfileShadow<
|
|||
}
|
||||
|
||||
export function updateProfileShadow(
|
||||
queryClient: QueryClient,
|
||||
did: string,
|
||||
value: Partial<ProfileShadow>,
|
||||
) {
|
||||
const cachedProfiles = findProfilesInCache(did)
|
||||
const cachedProfiles = findProfilesInCache(queryClient, did)
|
||||
for (let post of cachedProfiles) {
|
||||
shadows.set(post, {...shadows.get(post), ...value})
|
||||
}
|
||||
|
@ -90,6 +92,7 @@ function mergeShadow<TProfileView extends AppBskyActorDefs.ProfileView>(
|
|||
}
|
||||
|
||||
function* findProfilesInCache(
|
||||
queryClient: QueryClient,
|
||||
did: string,
|
||||
): Generator<AppBskyActorDefs.ProfileView, void> {
|
||||
yield* findAllProfilesInListMembersQueryData(queryClient, did)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue