Merge pull request #2679 from bluesky-social/hailey/check-blocks-load-profile
clear cache when blocking/unblocking and whenever we get blocked, better invalidation logic for `useProfileQuery`
This commit is contained in:
commit
4058174678
5 changed files with 48 additions and 13 deletions
|
@ -28,6 +28,7 @@ import {getModerationOpts} from '#/state/queries/preferences/moderation'
|
|||
import {KnownError} from '#/view/com/posts/FeedErrorMessage'
|
||||
import {embedViewRecordToPostView, getEmbeddedPost} from './util'
|
||||
import {useModerationOpts} from './preferences'
|
||||
import {queryClient} from 'lib/react-query'
|
||||
|
||||
type ActorDid = string
|
||||
type AuthorFilter =
|
||||
|
@ -444,3 +445,15 @@ function assertSomePostsPassModeration(feed: AppBskyFeedDefs.FeedViewPost[]) {
|
|||
throw new Error(KnownError.FeedNSFPublic)
|
||||
}
|
||||
}
|
||||
|
||||
export function resetProfilePostsQueries(did: string, timeout = 0) {
|
||||
setTimeout(() => {
|
||||
queryClient.resetQueries({
|
||||
predicate: query =>
|
||||
!!(
|
||||
query.queryKey[0] === 'post-feed' &&
|
||||
(query.queryKey[1] as string)?.includes(did)
|
||||
),
|
||||
})
|
||||
}, timeout)
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ import {updateProfileShadow} from '../cache/profile-shadow'
|
|||
import {uploadBlob} from '#/lib/api'
|
||||
import {until} from '#/lib/async/until'
|
||||
import {Shadow} from '#/state/cache/types'
|
||||
import {resetProfilePostsQueries} from '#/state/queries/post-feed'
|
||||
import {useToggleMutationQueue} from '#/lib/hooks/useToggleMutationQueue'
|
||||
import {RQKEY as RQKEY_MY_MUTED} from './my-muted-accounts'
|
||||
import {RQKEY as RQKEY_MY_BLOCKED} from './my-blocked-accounts'
|
||||
|
@ -26,16 +27,19 @@ import {track} from '#/lib/analytics/analytics'
|
|||
export const RQKEY = (did: string) => ['profile', did]
|
||||
export const profilesQueryKey = (handles: string[]) => ['profiles', handles]
|
||||
|
||||
export function useProfileQuery({did}: {did: string | undefined}) {
|
||||
const {currentAccount} = useSession()
|
||||
const isCurrentAccount = did === currentAccount?.did
|
||||
|
||||
export function useProfileQuery({
|
||||
did,
|
||||
staleTime = STALE.SECONDS.FIFTEEN,
|
||||
}: {
|
||||
did: string | undefined
|
||||
staleTime?: number
|
||||
}) {
|
||||
return useQuery({
|
||||
// WARNING
|
||||
// this staleTime is load-bearing
|
||||
// if you remove it, the UI infinite-loops
|
||||
// -prf
|
||||
staleTime: isCurrentAccount ? STALE.SECONDS.THIRTY : STALE.MINUTES.FIVE,
|
||||
staleTime,
|
||||
refetchOnWindowFocus: true,
|
||||
queryKey: RQKEY(did || ''),
|
||||
queryFn: async () => {
|
||||
|
@ -375,8 +379,9 @@ function useProfileBlockMutation() {
|
|||
{subject: did, createdAt: new Date().toISOString()},
|
||||
)
|
||||
},
|
||||
onSuccess() {
|
||||
onSuccess(_, {did}) {
|
||||
queryClient.invalidateQueries({queryKey: RQKEY_MY_BLOCKED()})
|
||||
resetProfilePostsQueries(did, 1000)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
@ -394,6 +399,9 @@ function useProfileUnblockMutation() {
|
|||
rkey,
|
||||
})
|
||||
},
|
||||
onSuccess(_, {did}) {
|
||||
resetProfilePostsQueries(did, 1000)
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue