diff options
author | Eric Bailey <git@esb.lol> | 2024-04-25 16:29:05 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-25 22:29:05 +0100 |
commit | 45d354cd0c76563de6d3d1146bebb750e0f6d4a0 (patch) | |
tree | 0939d1d6d91a4f812b1abeb005c6347b39692086 /src/state/queries/profile.ts | |
parent | d8c8e1e854654dbcf9585d0b3bd8c87d77df2e0f (diff) | |
download | voidsky-45d354cd0c76563de6d3d1146bebb750e0f6d4a0.tar.zst |
[Session] Add `useAgent` hook and replace (#3706)
* Hook it up * Memoize getAgent method * Use one shared reference --------- Co-authored-by: Dan Abramov <dan.abramov@gmail.com>
Diffstat (limited to 'src/state/queries/profile.ts')
-rw-r--r-- | src/state/queries/profile.ts | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/state/queries/profile.ts b/src/state/queries/profile.ts index 0d5d5e5bd..6c801426e 100644 --- a/src/state/queries/profile.ts +++ b/src/state/queries/profile.ts @@ -26,7 +26,7 @@ import {Shadow} from '#/state/cache/types' import {STALE} from '#/state/queries' import {resetProfilePostsQueries} from '#/state/queries/post-feed' import {updateProfileShadow} from '../cache/profile-shadow' -import {getAgent, useSession} from '../session' +import {useAgent, useSession} from '../session' import {RQKEY as RQKEY_MY_BLOCKED} from './my-blocked-accounts' import {RQKEY as RQKEY_MY_MUTED} from './my-muted-accounts' import {ThreadNode} from './post-thread' @@ -54,6 +54,7 @@ export function useProfileQuery({ staleTime?: number }) { const queryClient = useQueryClient() + const {getAgent} = useAgent() return useQuery<AppBskyActorDefs.ProfileViewDetailed>({ // WARNING // this staleTime is load-bearing @@ -78,6 +79,7 @@ export function useProfileQuery({ } export function useProfilesQuery({handles}: {handles: string[]}) { + const {getAgent} = useAgent() return useQuery({ staleTime: STALE.MINUTES.FIVE, queryKey: profilesQueryKey(handles), @@ -89,6 +91,7 @@ export function useProfilesQuery({handles}: {handles: string[]}) { } export function usePrefetchProfileQuery() { + const {getAgent} = useAgent() const queryClient = useQueryClient() const prefetchProfileQuery = useCallback( async (did: string) => { @@ -100,7 +103,7 @@ export function usePrefetchProfileQuery() { }, }) }, - [queryClient], + [queryClient, getAgent], ) return prefetchProfileQuery } @@ -116,6 +119,7 @@ interface ProfileUpdateParams { } export function useProfileUpdateMutation() { const queryClient = useQueryClient() + const {getAgent} = useAgent() return useMutation<void, Error, ProfileUpdateParams>({ mutationFn: async ({ profile, @@ -257,6 +261,7 @@ function useProfileFollowMutation( profile: Shadow<AppBskyActorDefs.ProfileViewDetailed>, ) { const {currentAccount} = useSession() + const {getAgent} = useAgent() const queryClient = useQueryClient() return useMutation<{uri: string; cid: string}, Error, {did: string}>({ mutationFn: async ({did}) => { @@ -283,6 +288,7 @@ function useProfileFollowMutation( function useProfileUnfollowMutation( logContext: LogEvents['profile:unfollow']['logContext'], ) { + const {getAgent} = useAgent() return useMutation<void, Error, {did: string; followUri: string}>({ mutationFn: async ({followUri}) => { logEvent('profile:unfollow', {logContext}) @@ -343,6 +349,7 @@ export function useProfileMuteMutationQueue( function useProfileMuteMutation() { const queryClient = useQueryClient() + const {getAgent} = useAgent() return useMutation<void, Error, {did: string}>({ mutationFn: async ({did}) => { await getAgent().mute(did) @@ -355,6 +362,7 @@ function useProfileMuteMutation() { function useProfileUnmuteMutation() { const queryClient = useQueryClient() + const {getAgent} = useAgent() return useMutation<void, Error, {did: string}>({ mutationFn: async ({did}) => { await getAgent().unmute(did) @@ -421,6 +429,7 @@ export function useProfileBlockMutationQueue( function useProfileBlockMutation() { const {currentAccount} = useSession() + const {getAgent} = useAgent() const queryClient = useQueryClient() return useMutation<{uri: string; cid: string}, Error, {did: string}>({ mutationFn: async ({did}) => { @@ -441,6 +450,7 @@ function useProfileBlockMutation() { function useProfileUnblockMutation() { const {currentAccount} = useSession() + const {getAgent} = useAgent() const queryClient = useQueryClient() return useMutation<void, Error, {did: string; blockUri: string}>({ mutationFn: async ({blockUri}) => { |