[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>zio/stable
parent
d8c8e1e854
commit
45d354cd0c
|
@ -6,7 +6,7 @@ import {useLingui} from '@lingui/react'
|
|||
|
||||
import {getLabelingServiceTitle} from '#/lib/moderation'
|
||||
import {ReportOption} from '#/lib/moderation/useReportOptions'
|
||||
import {getAgent} from '#/state/session'
|
||||
import {useAgent} from '#/state/session'
|
||||
import {CharProgress} from '#/view/com/composer/char-progress/CharProgress'
|
||||
import * as Toast from '#/view/com/util/Toast'
|
||||
import {atoms as a, native, useTheme} from '#/alf'
|
||||
|
@ -35,6 +35,7 @@ export function SubmitView({
|
|||
}) {
|
||||
const t = useTheme()
|
||||
const {_} = useLingui()
|
||||
const {getAgent} = useAgent()
|
||||
const [details, setDetails] = React.useState<string>('')
|
||||
const [submitting, setSubmitting] = React.useState<boolean>(false)
|
||||
const [selectedServices, setSelectedServices] = React.useState<string[]>([
|
||||
|
@ -90,6 +91,7 @@ export function SubmitView({
|
|||
selectedServices,
|
||||
onSubmitComplete,
|
||||
setError,
|
||||
getAgent,
|
||||
])
|
||||
|
||||
return (
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
import React from 'react'
|
||||
import {RichText as RichTextAPI} from '@atproto/api'
|
||||
|
||||
import {getAgent} from '#/state/session'
|
||||
import {useAgent} from '#/state/session'
|
||||
|
||||
export function useRichText(text: string): [RichTextAPI, boolean] {
|
||||
const [prevText, setPrevText] = React.useState(text)
|
||||
const [rawRT, setRawRT] = React.useState(() => new RichTextAPI({text}))
|
||||
const [resolvedRT, setResolvedRT] = React.useState<RichTextAPI | null>(null)
|
||||
const {getAgent} = useAgent()
|
||||
if (text !== prevText) {
|
||||
setPrevText(text)
|
||||
setRawRT(new RichTextAPI({text}))
|
||||
|
@ -27,7 +28,7 @@ export function useRichText(text: string): [RichTextAPI, boolean] {
|
|||
return () => {
|
||||
ignore = true
|
||||
}
|
||||
}, [text])
|
||||
}, [text, getAgent])
|
||||
const isResolving = resolvedRT === null
|
||||
return [resolvedRT ?? rawRT, isResolving]
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ import {useLingui} from '@lingui/react'
|
|||
import {useLabelInfo} from '#/lib/moderation/useLabelInfo'
|
||||
import {makeProfileLink} from '#/lib/routes/links'
|
||||
import {sanitizeHandle} from '#/lib/strings/handles'
|
||||
import {getAgent} from '#/state/session'
|
||||
import {useAgent} from '#/state/session'
|
||||
import * as Toast from '#/view/com/util/Toast'
|
||||
import {atoms as a, useBreakpoints, useTheme} from '#/alf'
|
||||
import {Button, ButtonText} from '#/components/Button'
|
||||
|
@ -173,6 +173,7 @@ function AppealForm({
|
|||
const {gtMobile} = useBreakpoints()
|
||||
const [details, setDetails] = React.useState('')
|
||||
const isAccountReport = 'did' in subject
|
||||
const {getAgent} = useAgent()
|
||||
|
||||
const onSubmit = async () => {
|
||||
try {
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
import React from 'react'
|
||||
import {View} from 'react-native'
|
||||
import {useSafeAreaInsets} from 'react-native-safe-area-context'
|
||||
import {useLingui} from '@lingui/react'
|
||||
import {msg, Trans} from '@lingui/macro'
|
||||
import {useOnboardingDispatch} from '#/state/shell'
|
||||
import {getAgent, isSessionDeactivated, useSessionApi} from '#/state/session'
|
||||
import {logger} from '#/logger'
|
||||
import {pluralize} from '#/lib/strings/helpers'
|
||||
import {useLingui} from '@lingui/react'
|
||||
|
||||
import {atoms as a, useTheme, useBreakpoints} from '#/alf'
|
||||
import {Button, ButtonIcon, ButtonText} from '#/components/Button'
|
||||
import {Text, P} from '#/components/Typography'
|
||||
import {pluralize} from '#/lib/strings/helpers'
|
||||
import {logger} from '#/logger'
|
||||
import {isWeb} from '#/platform/detection'
|
||||
import {isSessionDeactivated, useAgent, useSessionApi} from '#/state/session'
|
||||
import {useOnboardingDispatch} from '#/state/shell'
|
||||
import {ScrollView} from '#/view/com/util/Views'
|
||||
import {Loader} from '#/components/Loader'
|
||||
import {Logo} from '#/view/icons/Logo'
|
||||
import {atoms as a, useBreakpoints, useTheme} from '#/alf'
|
||||
import {Button, ButtonIcon, ButtonText} from '#/components/Button'
|
||||
import {Loader} from '#/components/Loader'
|
||||
import {P, Text} from '#/components/Typography'
|
||||
|
||||
const COL_WIDTH = 400
|
||||
|
||||
|
@ -25,6 +25,7 @@ export function Deactivated() {
|
|||
const {gtMobile} = useBreakpoints()
|
||||
const onboardingDispatch = useOnboardingDispatch()
|
||||
const {logout} = useSessionApi()
|
||||
const {getAgent} = useAgent()
|
||||
|
||||
const [isProcessing, setProcessing] = React.useState(false)
|
||||
const [estimatedTime, setEstimatedTime] = React.useState<string | undefined>(
|
||||
|
@ -56,7 +57,13 @@ export function Deactivated() {
|
|||
} finally {
|
||||
setProcessing(false)
|
||||
}
|
||||
}, [setProcessing, setEstimatedTime, setPlaceInQueue, onboardingDispatch])
|
||||
}, [
|
||||
setProcessing,
|
||||
setEstimatedTime,
|
||||
setPlaceInQueue,
|
||||
onboardingDispatch,
|
||||
getAgent,
|
||||
])
|
||||
|
||||
React.useEffect(() => {
|
||||
checkStatus()
|
||||
|
|
|
@ -8,7 +8,7 @@ import {BSKY_APP_ACCOUNT_DID} from '#/lib/constants'
|
|||
import {logEvent} from '#/lib/statsig/statsig'
|
||||
import {logger} from '#/logger'
|
||||
import {useSetSaveFeedsMutation} from '#/state/queries/preferences'
|
||||
import {getAgent} from '#/state/session'
|
||||
import {useAgent} from '#/state/session'
|
||||
import {useOnboardingDispatch} from '#/state/shell'
|
||||
import {
|
||||
DescriptionText,
|
||||
|
@ -38,6 +38,7 @@ export function StepFinished() {
|
|||
const onboardDispatch = useOnboardingDispatch()
|
||||
const [saving, setSaving] = React.useState(false)
|
||||
const {mutateAsync: saveFeeds} = useSetSaveFeedsMutation()
|
||||
const {getAgent} = useAgent()
|
||||
|
||||
const finishOnboarding = React.useCallback(async () => {
|
||||
setSaving(true)
|
||||
|
@ -81,7 +82,7 @@ export function StepFinished() {
|
|||
track('OnboardingV2:StepFinished:End')
|
||||
track('OnboardingV2:Complete')
|
||||
logEvent('onboarding:finished:nextPressed', {})
|
||||
}, [state, dispatch, onboardDispatch, setSaving, saveFeeds, track])
|
||||
}, [state, dispatch, onboardDispatch, setSaving, saveFeeds, track, getAgent])
|
||||
|
||||
React.useEffect(() => {
|
||||
track('OnboardingV2:StepFinished:Start')
|
||||
|
|
|
@ -8,7 +8,7 @@ import {useAnalytics} from '#/lib/analytics/analytics'
|
|||
import {logEvent} from '#/lib/statsig/statsig'
|
||||
import {capitalize} from '#/lib/strings/capitalize'
|
||||
import {logger} from '#/logger'
|
||||
import {getAgent} from '#/state/session'
|
||||
import {useAgent} from '#/state/session'
|
||||
import {useOnboardingDispatch} from '#/state/shell'
|
||||
import {
|
||||
DescriptionText,
|
||||
|
@ -39,6 +39,7 @@ export function StepInterests() {
|
|||
state.interestsStepResults.selectedInterests.map(i => i),
|
||||
)
|
||||
const onboardDispatch = useOnboardingDispatch()
|
||||
const {getAgent} = useAgent()
|
||||
const {isLoading, isError, error, data, refetch, isFetching} = useQuery({
|
||||
queryKey: ['interests'],
|
||||
queryFn: async () => {
|
||||
|
|
|
@ -9,7 +9,7 @@ import {FEEDBACK_FORM_URL} from '#/lib/constants'
|
|||
import {logEvent} from '#/lib/statsig/statsig'
|
||||
import {createFullHandle} from '#/lib/strings/handles'
|
||||
import {useServiceQuery} from '#/state/queries/service'
|
||||
import {getAgent} from '#/state/session'
|
||||
import {useAgent} from '#/state/session'
|
||||
import {LoggedOutLayout} from '#/view/com/util/layouts/LoggedOutLayout'
|
||||
import {
|
||||
initialState,
|
||||
|
@ -35,6 +35,7 @@ export function Signup({onPressBack}: {onPressBack: () => void}) {
|
|||
const [state, dispatch] = React.useReducer(reducer, initialState)
|
||||
const submit = useSubmitSignup({state, dispatch})
|
||||
const {gtMobile} = useBreakpoints()
|
||||
const {getAgent} = useAgent()
|
||||
|
||||
const {
|
||||
data: serviceInfo,
|
||||
|
@ -113,6 +114,7 @@ export function Signup({onPressBack}: {onPressBack: () => void}) {
|
|||
state.serviceDescription?.phoneVerificationRequired,
|
||||
state.userDomain,
|
||||
submit,
|
||||
getAgent,
|
||||
])
|
||||
|
||||
const onBackPress = React.useCallback(() => {
|
||||
|
|
|
@ -5,7 +5,7 @@ import {useQuery, useQueryClient} from '@tanstack/react-query'
|
|||
import {isJustAMute} from '#/lib/moderation'
|
||||
import {logger} from '#/logger'
|
||||
import {STALE} from '#/state/queries'
|
||||
import {getAgent} from '#/state/session'
|
||||
import {useAgent} from '#/state/session'
|
||||
import {DEFAULT_LOGGED_OUT_PREFERENCES, useModerationOpts} from './preferences'
|
||||
|
||||
const DEFAULT_MOD_OPTS = {
|
||||
|
@ -18,6 +18,7 @@ export const RQKEY = (prefix: string) => [RQKEY_ROOT, prefix]
|
|||
|
||||
export function useActorAutocompleteQuery(prefix: string) {
|
||||
const moderationOpts = useModerationOpts()
|
||||
const {getAgent} = useAgent()
|
||||
|
||||
prefix = prefix.toLowerCase()
|
||||
|
||||
|
@ -46,6 +47,7 @@ export type ActorAutocompleteFn = ReturnType<typeof useActorAutocompleteFn>
|
|||
export function useActorAutocompleteFn() {
|
||||
const queryClient = useQueryClient()
|
||||
const moderationOpts = useModerationOpts()
|
||||
const {getAgent} = useAgent()
|
||||
|
||||
return React.useCallback(
|
||||
async ({query, limit = 8}: {query: string; limit?: number}) => {
|
||||
|
@ -74,7 +76,7 @@ export function useActorAutocompleteFn() {
|
|||
moderationOpts || DEFAULT_MOD_OPTS,
|
||||
)
|
||||
},
|
||||
[queryClient, moderationOpts],
|
||||
[queryClient, moderationOpts, getAgent],
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ import {AppBskyActorDefs} from '@atproto/api'
|
|||
import {QueryClient, useQuery} from '@tanstack/react-query'
|
||||
|
||||
import {STALE} from '#/state/queries'
|
||||
import {getAgent} from '#/state/session'
|
||||
import {useAgent} from '#/state/session'
|
||||
|
||||
const RQKEY_ROOT = 'actor-search'
|
||||
export const RQKEY = (query: string) => [RQKEY_ROOT, query]
|
||||
|
@ -14,6 +14,7 @@ export function useActorSearch({
|
|||
query: string
|
||||
enabled?: boolean
|
||||
}) {
|
||||
const {getAgent} = useAgent()
|
||||
return useQuery<AppBskyActorDefs.ProfileView[]>({
|
||||
staleTime: STALE.MINUTES.ONE,
|
||||
queryKey: RQKEY(query || ''),
|
||||
|
|
|
@ -2,12 +2,13 @@ import {ComAtprotoServerCreateAppPassword} from '@atproto/api'
|
|||
import {useMutation, useQuery, useQueryClient} from '@tanstack/react-query'
|
||||
|
||||
import {STALE} from '#/state/queries'
|
||||
import {getAgent} from '../session'
|
||||
import {useAgent} from '../session'
|
||||
|
||||
const RQKEY_ROOT = 'app-passwords'
|
||||
export const RQKEY = () => [RQKEY_ROOT]
|
||||
|
||||
export function useAppPasswordsQuery() {
|
||||
const {getAgent} = useAgent()
|
||||
return useQuery({
|
||||
staleTime: STALE.MINUTES.FIVE,
|
||||
queryKey: RQKEY(),
|
||||
|
@ -20,6 +21,7 @@ export function useAppPasswordsQuery() {
|
|||
|
||||
export function useAppPasswordCreateMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
return useMutation<
|
||||
ComAtprotoServerCreateAppPassword.OutputSchema,
|
||||
Error,
|
||||
|
@ -42,6 +44,7 @@ export function useAppPasswordCreateMutation() {
|
|||
|
||||
export function useAppPasswordDeleteMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
return useMutation<void, Error, {name: string}>({
|
||||
mutationFn: async ({name}) => {
|
||||
await getAgent().com.atproto.server.revokeAppPassword({
|
||||
|
|
|
@ -17,7 +17,7 @@ import {sanitizeDisplayName} from '#/lib/strings/display-names'
|
|||
import {sanitizeHandle} from '#/lib/strings/handles'
|
||||
import {STALE} from '#/state/queries'
|
||||
import {usePreferencesQuery} from '#/state/queries/preferences'
|
||||
import {getAgent, useSession} from '#/state/session'
|
||||
import {useAgent, useSession} from '#/state/session'
|
||||
import {router} from '#/routes'
|
||||
|
||||
export type FeedSourceFeedInfo = {
|
||||
|
@ -140,6 +140,7 @@ export function getAvatarTypeFromUri(uri: string) {
|
|||
|
||||
export function useFeedSourceInfoQuery({uri}: {uri: string}) {
|
||||
const type = getFeedTypeFromUri(uri)
|
||||
const {getAgent} = useAgent()
|
||||
|
||||
return useQuery({
|
||||
staleTime: STALE.INFINITY,
|
||||
|
@ -166,6 +167,7 @@ export function useFeedSourceInfoQuery({uri}: {uri: string}) {
|
|||
export const useGetPopularFeedsQueryKey = ['getPopularFeeds']
|
||||
|
||||
export function useGetPopularFeedsQuery() {
|
||||
const {getAgent} = useAgent()
|
||||
return useInfiniteQuery<
|
||||
AppBskyUnspeccedGetPopularFeedGenerators.OutputSchema,
|
||||
Error,
|
||||
|
@ -187,6 +189,7 @@ export function useGetPopularFeedsQuery() {
|
|||
}
|
||||
|
||||
export function useSearchPopularFeedsMutation() {
|
||||
const {getAgent} = useAgent()
|
||||
return useMutation({
|
||||
mutationFn: async (query: string) => {
|
||||
const res = await getAgent().app.bsky.unspecced.getPopularFeedGenerators({
|
||||
|
@ -238,6 +241,7 @@ const pinnedFeedInfosQueryKeyRoot = 'pinnedFeedsInfos'
|
|||
|
||||
export function usePinnedFeedsInfos() {
|
||||
const {hasSession} = useSession()
|
||||
const {getAgent} = useAgent()
|
||||
const {data: preferences, isLoading: isLoadingPrefs} = usePreferencesQuery()
|
||||
const pinnedUris = preferences?.feeds?.pinned ?? []
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ import React from 'react'
|
|||
import {useMutation, useQueryClient} from '@tanstack/react-query'
|
||||
|
||||
import {STALE} from '#/state/queries'
|
||||
import {getAgent} from '#/state/session'
|
||||
import {useAgent} from '#/state/session'
|
||||
|
||||
const handleQueryKeyRoot = 'handle'
|
||||
const fetchHandleQueryKey = (handleOrDid: string) => [
|
||||
|
@ -14,6 +14,7 @@ const fetchDidQueryKey = (handleOrDid: string) => [didQueryKeyRoot, handleOrDid]
|
|||
|
||||
export function useFetchHandle() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
|
||||
return React.useCallback(
|
||||
async (handleOrDid: string) => {
|
||||
|
@ -27,12 +28,13 @@ export function useFetchHandle() {
|
|||
}
|
||||
return handleOrDid
|
||||
},
|
||||
[queryClient],
|
||||
[queryClient, getAgent],
|
||||
)
|
||||
}
|
||||
|
||||
export function useUpdateHandleMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async ({handle}: {handle: string}) => {
|
||||
|
@ -48,6 +50,7 @@ export function useUpdateHandleMutation() {
|
|||
|
||||
export function useFetchDid() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
|
||||
return React.useCallback(
|
||||
async (handleOrDid: string) => {
|
||||
|
@ -64,6 +67,6 @@ export function useFetchDid() {
|
|||
},
|
||||
})
|
||||
},
|
||||
[queryClient],
|
||||
[queryClient, getAgent],
|
||||
)
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ import {useQuery} from '@tanstack/react-query'
|
|||
|
||||
import {cleanError} from '#/lib/strings/errors'
|
||||
import {STALE} from '#/state/queries'
|
||||
import {getAgent} from '#/state/session'
|
||||
import {useAgent} from '#/state/session'
|
||||
|
||||
function isInviteAvailable(invite: ComAtprotoServerDefs.InviteCode): boolean {
|
||||
return invite.available - invite.uses.length > 0 && !invite.disabled
|
||||
|
@ -16,6 +16,7 @@ export type InviteCodesQueryResponse = Exclude<
|
|||
undefined
|
||||
>
|
||||
export function useInviteCodesQuery() {
|
||||
const {getAgent} = useAgent()
|
||||
return useQuery({
|
||||
staleTime: STALE.MINUTES.FIVE,
|
||||
queryKey: [inviteCodesQueryKeyRoot],
|
||||
|
|
|
@ -5,7 +5,7 @@ import {z} from 'zod'
|
|||
import {labelersDetailedInfoQueryKeyRoot} from '#/lib/react-query'
|
||||
import {STALE} from '#/state/queries'
|
||||
import {preferencesQueryKey} from '#/state/queries/preferences'
|
||||
import {getAgent} from '#/state/session'
|
||||
import {useAgent} from '#/state/session'
|
||||
|
||||
const labelerInfoQueryKeyRoot = 'labeler-info'
|
||||
export const labelerInfoQueryKey = (did: string) => [
|
||||
|
@ -31,6 +31,7 @@ export function useLabelerInfoQuery({
|
|||
did?: string
|
||||
enabled?: boolean
|
||||
}) {
|
||||
const {getAgent} = useAgent()
|
||||
return useQuery({
|
||||
enabled: !!did && enabled !== false,
|
||||
queryKey: labelerInfoQueryKey(did as string),
|
||||
|
@ -45,6 +46,7 @@ export function useLabelerInfoQuery({
|
|||
}
|
||||
|
||||
export function useLabelersInfoQuery({dids}: {dids: string[]}) {
|
||||
const {getAgent} = useAgent()
|
||||
return useQuery({
|
||||
enabled: !!dids.length,
|
||||
queryKey: labelersInfoQueryKey(dids),
|
||||
|
@ -56,6 +58,7 @@ export function useLabelersInfoQuery({dids}: {dids: string[]}) {
|
|||
}
|
||||
|
||||
export function useLabelersDetailedInfoQuery({dids}: {dids: string[]}) {
|
||||
const {getAgent} = useAgent()
|
||||
return useQuery({
|
||||
enabled: !!dids.length,
|
||||
queryKey: labelersDetailedInfoQueryKey(dids),
|
||||
|
@ -73,6 +76,7 @@ export function useLabelersDetailedInfoQuery({dids}: {dids: string[]}) {
|
|||
|
||||
export function useLabelerSubscriptionMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
|
||||
return useMutation({
|
||||
async mutationFn({did, subscribe}: {did: string; subscribe: boolean}) {
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
import {useMutation} from '@tanstack/react-query'
|
||||
|
||||
import {getAgent} from '#/state/session'
|
||||
import {useAgent} from '#/state/session'
|
||||
|
||||
export function useLikeMutation() {
|
||||
const {getAgent} = useAgent()
|
||||
return useMutation({
|
||||
mutationFn: async ({uri, cid}: {uri: string; cid: string}) => {
|
||||
const res = await getAgent().like(uri, cid)
|
||||
|
@ -12,6 +13,7 @@ export function useLikeMutation() {
|
|||
}
|
||||
|
||||
export function useUnlikeMutation() {
|
||||
const {getAgent} = useAgent()
|
||||
return useMutation({
|
||||
mutationFn: async ({uri}: {uri: string}) => {
|
||||
await getAgent().deleteLike(uri)
|
||||
|
|
|
@ -7,7 +7,7 @@ import {
|
|||
} from '@tanstack/react-query'
|
||||
|
||||
import {STALE} from '#/state/queries'
|
||||
import {getAgent} from '#/state/session'
|
||||
import {useAgent} from '#/state/session'
|
||||
|
||||
const PAGE_SIZE = 30
|
||||
type RQPageParam = string | undefined
|
||||
|
@ -16,6 +16,7 @@ const RQKEY_ROOT = 'list-members'
|
|||
export const RQKEY = (uri: string) => [RQKEY_ROOT, uri]
|
||||
|
||||
export function useListMembersQuery(uri: string) {
|
||||
const {getAgent} = useAgent()
|
||||
return useInfiniteQuery<
|
||||
AppBskyGraphGetList.OutputSchema,
|
||||
Error,
|
||||
|
|
|
@ -19,7 +19,7 @@ import {useMutation, useQuery, useQueryClient} from '@tanstack/react-query'
|
|||
|
||||
import {STALE} from '#/state/queries'
|
||||
import {RQKEY as LIST_MEMBERS_RQKEY} from '#/state/queries/list-members'
|
||||
import {getAgent, useSession} from '#/state/session'
|
||||
import {useAgent, useSession} from '#/state/session'
|
||||
|
||||
// sanity limit is SANITY_PAGE_LIMIT*PAGE_SIZE total records
|
||||
const SANITY_PAGE_LIMIT = 1000
|
||||
|
@ -40,6 +40,7 @@ export interface ListMembersip {
|
|||
*/
|
||||
export function useDangerousListMembershipsQuery() {
|
||||
const {currentAccount} = useSession()
|
||||
const {getAgent} = useAgent()
|
||||
return useQuery<ListMembersip[]>({
|
||||
staleTime: STALE.MINUTES.FIVE,
|
||||
queryKey: RQKEY(),
|
||||
|
@ -91,6 +92,7 @@ export function getMembership(
|
|||
|
||||
export function useListMembershipAddMutation() {
|
||||
const {currentAccount} = useSession()
|
||||
const {getAgent} = useAgent()
|
||||
const queryClient = useQueryClient()
|
||||
return useMutation<
|
||||
{uri: string; cid: string},
|
||||
|
@ -149,6 +151,7 @@ export function useListMembershipAddMutation() {
|
|||
|
||||
export function useListMembershipRemoveMutation() {
|
||||
const {currentAccount} = useSession()
|
||||
const {getAgent} = useAgent()
|
||||
const queryClient = useQueryClient()
|
||||
return useMutation<
|
||||
void,
|
||||
|
|
|
@ -13,7 +13,7 @@ import chunk from 'lodash.chunk'
|
|||
import {uploadBlob} from '#/lib/api'
|
||||
import {until} from '#/lib/async/until'
|
||||
import {STALE} from '#/state/queries'
|
||||
import {getAgent, useSession} from '../session'
|
||||
import {useAgent, useSession} from '../session'
|
||||
import {invalidate as invalidateMyLists} from './my-lists'
|
||||
import {RQKEY as PROFILE_LISTS_RQKEY} from './profile-lists'
|
||||
|
||||
|
@ -21,6 +21,7 @@ const RQKEY_ROOT = 'list'
|
|||
export const RQKEY = (uri: string) => [RQKEY_ROOT, uri]
|
||||
|
||||
export function useListQuery(uri?: string) {
|
||||
const {getAgent} = useAgent()
|
||||
return useQuery<AppBskyGraphDefs.ListView, Error>({
|
||||
staleTime: STALE.MINUTES.ONE,
|
||||
queryKey: RQKEY(uri || ''),
|
||||
|
@ -48,6 +49,7 @@ export interface ListCreateMutateParams {
|
|||
export function useListCreateMutation() {
|
||||
const {currentAccount} = useSession()
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
return useMutation<{uri: string; cid: string}, Error, ListCreateMutateParams>(
|
||||
{
|
||||
async mutationFn({
|
||||
|
@ -114,6 +116,7 @@ export interface ListMetadataMutateParams {
|
|||
}
|
||||
export function useListMetadataMutation() {
|
||||
const {currentAccount} = useSession()
|
||||
const {getAgent} = useAgent()
|
||||
const queryClient = useQueryClient()
|
||||
return useMutation<
|
||||
{uri: string; cid: string},
|
||||
|
@ -181,6 +184,7 @@ export function useListMetadataMutation() {
|
|||
|
||||
export function useListDeleteMutation() {
|
||||
const {currentAccount} = useSession()
|
||||
const {getAgent} = useAgent()
|
||||
const queryClient = useQueryClient()
|
||||
return useMutation<void, Error, {uri: string}>({
|
||||
mutationFn: async ({uri}) => {
|
||||
|
@ -249,6 +253,7 @@ export function useListDeleteMutation() {
|
|||
|
||||
export function useListMuteMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
return useMutation<void, Error, {uri: string; mute: boolean}>({
|
||||
mutationFn: async ({uri, mute}) => {
|
||||
if (mute) {
|
||||
|
@ -275,6 +280,7 @@ export function useListMuteMutation() {
|
|||
|
||||
export function useListBlockMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
return useMutation<void, Error, {uri: string; block: boolean}>({
|
||||
mutationFn: async ({uri, block}) => {
|
||||
if (block) {
|
||||
|
|
|
@ -6,13 +6,14 @@ import {
|
|||
useInfiniteQuery,
|
||||
} from '@tanstack/react-query'
|
||||
|
||||
import {getAgent} from '#/state/session'
|
||||
import {useAgent} from '#/state/session'
|
||||
|
||||
const RQKEY_ROOT = 'my-blocked-accounts'
|
||||
export const RQKEY = () => [RQKEY_ROOT]
|
||||
type RQPageParam = string | undefined
|
||||
|
||||
export function useMyBlockedAccountsQuery() {
|
||||
const {getAgent} = useAgent()
|
||||
return useInfiniteQuery<
|
||||
AppBskyGraphGetBlocks.OutputSchema,
|
||||
Error,
|
||||
|
|
|
@ -3,7 +3,7 @@ import {QueryClient, useQuery} from '@tanstack/react-query'
|
|||
|
||||
import {accumulate} from '#/lib/async/accumulate'
|
||||
import {STALE} from '#/state/queries'
|
||||
import {getAgent, useSession} from '#/state/session'
|
||||
import {useAgent, useSession} from '#/state/session'
|
||||
|
||||
export type MyListsFilter =
|
||||
| 'all'
|
||||
|
@ -16,6 +16,7 @@ export const RQKEY = (filter: MyListsFilter) => [RQKEY_ROOT, filter]
|
|||
|
||||
export function useMyListsQuery(filter: MyListsFilter) {
|
||||
const {currentAccount} = useSession()
|
||||
const {getAgent} = useAgent()
|
||||
return useQuery<AppBskyGraphDefs.ListView[]>({
|
||||
staleTime: STALE.MINUTES.ONE,
|
||||
queryKey: RQKEY(filter),
|
||||
|
|
|
@ -6,13 +6,14 @@ import {
|
|||
useInfiniteQuery,
|
||||
} from '@tanstack/react-query'
|
||||
|
||||
import {getAgent} from '#/state/session'
|
||||
import {useAgent} from '#/state/session'
|
||||
|
||||
const RQKEY_ROOT = 'my-muted-accounts'
|
||||
export const RQKEY = () => [RQKEY_ROOT]
|
||||
type RQPageParam = string | undefined
|
||||
|
||||
export function useMyMutedAccountsQuery() {
|
||||
const {getAgent} = useAgent()
|
||||
return useInfiniteQuery<
|
||||
AppBskyGraphGetMutes.OutputSchema,
|
||||
Error,
|
||||
|
|
|
@ -27,7 +27,7 @@ import {
|
|||
} from '@tanstack/react-query'
|
||||
|
||||
import {useMutedThreads} from '#/state/muted-threads'
|
||||
import {getAgent} from '#/state/session'
|
||||
import {useAgent} from '#/state/session'
|
||||
import {STALE} from '..'
|
||||
import {useModerationOpts} from '../preferences'
|
||||
import {embedViewRecordToPostView, getEmbeddedPost} from '../util'
|
||||
|
@ -47,6 +47,7 @@ export function RQKEY() {
|
|||
}
|
||||
|
||||
export function useNotificationFeedQuery(opts?: {enabled?: boolean}) {
|
||||
const {getAgent} = useAgent()
|
||||
const queryClient = useQueryClient()
|
||||
const moderationOpts = useModerationOpts()
|
||||
const threadMutes = useMutedThreads()
|
||||
|
|
|
@ -12,7 +12,7 @@ import BroadcastChannel from '#/lib/broadcast'
|
|||
import {logger} from '#/logger'
|
||||
import {isNative} from '#/platform/detection'
|
||||
import {useMutedThreads} from '#/state/muted-threads'
|
||||
import {getAgent, useSession} from '#/state/session'
|
||||
import {useAgent, useSession} from '#/state/session'
|
||||
import {useModerationOpts} from '../preferences'
|
||||
import {truncateAndInvalidate} from '../util'
|
||||
import {RQKEY as RQKEY_NOTIFS} from './feed'
|
||||
|
@ -46,6 +46,7 @@ const apiContext = React.createContext<ApiContext>({
|
|||
|
||||
export function Provider({children}: React.PropsWithChildren<{}>) {
|
||||
const {hasSession} = useSession()
|
||||
const {getAgent} = useAgent()
|
||||
const queryClient = useQueryClient()
|
||||
const moderationOpts = useModerationOpts()
|
||||
const threadMutes = useMutedThreads()
|
||||
|
@ -197,7 +198,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
|
|||
}
|
||||
},
|
||||
}
|
||||
}, [setNumUnread, queryClient, moderationOpts, threadMutes])
|
||||
}, [setNumUnread, queryClient, moderationOpts, threadMutes, getAgent])
|
||||
checkUnreadRef.current = api.checkUnread
|
||||
|
||||
return (
|
||||
|
|
|
@ -4,6 +4,7 @@ import {
|
|||
AppBskyFeedDefs,
|
||||
AppBskyFeedPost,
|
||||
AtUri,
|
||||
BskyAgent,
|
||||
ModerationDecision,
|
||||
} from '@atproto/api'
|
||||
import {
|
||||
|
@ -19,7 +20,7 @@ import {moderatePost_wrapped as moderatePost} from '#/lib/moderatePost_wrapped'
|
|||
import {logger} from '#/logger'
|
||||
import {STALE} from '#/state/queries'
|
||||
import {DEFAULT_LOGGED_OUT_PREFERENCES} from '#/state/queries/preferences/const'
|
||||
import {getAgent} from '#/state/session'
|
||||
import {useAgent} from '#/state/session'
|
||||
import {AuthorFeedAPI} from 'lib/api/feed/author'
|
||||
import {CustomFeedAPI} from 'lib/api/feed/custom'
|
||||
import {FollowingFeedAPI} from 'lib/api/feed/following'
|
||||
|
@ -104,6 +105,7 @@ export function usePostFeedQuery(
|
|||
const queryClient = useQueryClient()
|
||||
const feedTuners = useFeedTuners(feedDesc)
|
||||
const moderationOpts = useModerationOpts()
|
||||
const {getAgent} = useAgent()
|
||||
const enabled = opts?.enabled !== false && Boolean(moderationOpts)
|
||||
const lastRun = useRef<{
|
||||
data: InfiniteData<FeedPageUnselected>
|
||||
|
@ -142,6 +144,7 @@ export function usePostFeedQuery(
|
|||
feedDesc,
|
||||
feedParams: params || {},
|
||||
feedTuners,
|
||||
getAgent,
|
||||
}),
|
||||
cursor: undefined,
|
||||
}
|
||||
|
@ -372,10 +375,12 @@ function createApi({
|
|||
feedDesc,
|
||||
feedParams,
|
||||
feedTuners,
|
||||
getAgent,
|
||||
}: {
|
||||
feedDesc: FeedDescriptor
|
||||
feedParams: FeedParams
|
||||
feedTuners: FeedTunerFn[]
|
||||
getAgent: () => BskyAgent
|
||||
}) {
|
||||
if (feedDesc === 'home') {
|
||||
if (feedParams.mergeFeedEnabled) {
|
||||
|
|
|
@ -6,7 +6,7 @@ import {
|
|||
useInfiniteQuery,
|
||||
} from '@tanstack/react-query'
|
||||
|
||||
import {getAgent} from '#/state/session'
|
||||
import {useAgent} from '#/state/session'
|
||||
|
||||
const PAGE_SIZE = 30
|
||||
type RQPageParam = string | undefined
|
||||
|
@ -16,6 +16,7 @@ const RQKEY_ROOT = 'liked-by'
|
|||
export const RQKEY = (resolvedUri: string) => [RQKEY_ROOT, resolvedUri]
|
||||
|
||||
export function useLikedByQuery(resolvedUri: string | undefined) {
|
||||
const {getAgent} = useAgent()
|
||||
return useInfiniteQuery<
|
||||
AppBskyFeedGetLikes.OutputSchema,
|
||||
Error,
|
||||
|
|
|
@ -6,7 +6,7 @@ import {
|
|||
useInfiniteQuery,
|
||||
} from '@tanstack/react-query'
|
||||
|
||||
import {getAgent} from '#/state/session'
|
||||
import {useAgent} from '#/state/session'
|
||||
|
||||
const PAGE_SIZE = 30
|
||||
type RQPageParam = string | undefined
|
||||
|
@ -16,6 +16,7 @@ const RQKEY_ROOT = 'post-reposted-by'
|
|||
export const RQKEY = (resolvedUri: string) => [RQKEY_ROOT, resolvedUri]
|
||||
|
||||
export function usePostRepostedByQuery(resolvedUri: string | undefined) {
|
||||
const {getAgent} = useAgent()
|
||||
return useInfiniteQuery<
|
||||
AppBskyFeedGetRepostedBy.OutputSchema,
|
||||
Error,
|
||||
|
|
|
@ -7,7 +7,7 @@ import {
|
|||
import {QueryClient, useQuery, useQueryClient} from '@tanstack/react-query'
|
||||
|
||||
import {UsePreferencesQueryResponse} from '#/state/queries/preferences/types'
|
||||
import {getAgent} from '#/state/session'
|
||||
import {useAgent} from '#/state/session'
|
||||
import {findAllPostsInQueryData as findAllPostsInSearchQueryData} from 'state/queries/search-posts'
|
||||
import {findAllPostsInQueryData as findAllPostsInNotifsQueryData} from './notifications/feed'
|
||||
import {findAllPostsInQueryData as findAllPostsInFeedQueryData} from './post-feed'
|
||||
|
@ -66,6 +66,7 @@ export type ThreadNode =
|
|||
|
||||
export function usePostThreadQuery(uri: string | undefined) {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
return useQuery<ThreadNode, Error>({
|
||||
gcTime: 0,
|
||||
queryKey: RQKEY(uri || ''),
|
||||
|
|
|
@ -7,13 +7,14 @@ import {useToggleMutationQueue} from '#/lib/hooks/useToggleMutationQueue'
|
|||
import {logEvent, LogEvents, toClout} from '#/lib/statsig/statsig'
|
||||
import {updatePostShadow} from '#/state/cache/post-shadow'
|
||||
import {Shadow} from '#/state/cache/types'
|
||||
import {getAgent, useSession} from '#/state/session'
|
||||
import {useAgent, useSession} from '#/state/session'
|
||||
import {findProfileQueryData} from './profile'
|
||||
|
||||
const RQKEY_ROOT = 'post'
|
||||
export const RQKEY = (postUri: string) => [RQKEY_ROOT, postUri]
|
||||
|
||||
export function usePostQuery(uri: string | undefined) {
|
||||
const {getAgent} = useAgent()
|
||||
return useQuery<AppBskyFeedDefs.PostView>({
|
||||
queryKey: RQKEY(uri || ''),
|
||||
async queryFn() {
|
||||
|
@ -30,6 +31,7 @@ export function usePostQuery(uri: string | undefined) {
|
|||
|
||||
export function useGetPost() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
return useCallback(
|
||||
async ({uri}: {uri: string}) => {
|
||||
return queryClient.fetchQuery({
|
||||
|
@ -56,7 +58,7 @@ export function useGetPost() {
|
|||
},
|
||||
})
|
||||
},
|
||||
[queryClient],
|
||||
[queryClient, getAgent],
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -125,6 +127,7 @@ function usePostLikeMutation(
|
|||
const {currentAccount} = useSession()
|
||||
const queryClient = useQueryClient()
|
||||
const postAuthor = post.author
|
||||
const {getAgent} = useAgent()
|
||||
return useMutation<
|
||||
{uri: string}, // responds with the uri of the like
|
||||
Error,
|
||||
|
@ -162,6 +165,7 @@ function usePostLikeMutation(
|
|||
function usePostUnlikeMutation(
|
||||
logContext: LogEvents['post:unlike']['logContext'],
|
||||
) {
|
||||
const {getAgent} = useAgent()
|
||||
return useMutation<void, Error, {postUri: string; likeUri: string}>({
|
||||
mutationFn: ({likeUri}) => {
|
||||
logEvent('post:unlike', {logContext})
|
||||
|
@ -234,6 +238,7 @@ export function usePostRepostMutationQueue(
|
|||
function usePostRepostMutation(
|
||||
logContext: LogEvents['post:repost']['logContext'],
|
||||
) {
|
||||
const {getAgent} = useAgent()
|
||||
return useMutation<
|
||||
{uri: string}, // responds with the uri of the repost
|
||||
Error,
|
||||
|
@ -252,6 +257,7 @@ function usePostRepostMutation(
|
|||
function usePostUnrepostMutation(
|
||||
logContext: LogEvents['post:unrepost']['logContext'],
|
||||
) {
|
||||
const {getAgent} = useAgent()
|
||||
return useMutation<void, Error, {postUri: string; repostUri: string}>({
|
||||
mutationFn: ({repostUri}) => {
|
||||
logEvent('post:unrepost', {logContext})
|
||||
|
@ -265,6 +271,7 @@ function usePostUnrepostMutation(
|
|||
|
||||
export function usePostDeleteMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
return useMutation<void, Error, {uri: string}>({
|
||||
mutationFn: async ({uri}) => {
|
||||
await getAgent().deletePost(uri)
|
||||
|
|
|
@ -22,7 +22,7 @@ import {
|
|||
ThreadViewPreferences,
|
||||
UsePreferencesQueryResponse,
|
||||
} from '#/state/queries/preferences/types'
|
||||
import {getAgent, useSession} from '#/state/session'
|
||||
import {useAgent, useSession} from '#/state/session'
|
||||
import {saveLabelers} from '#/state/session/agent-config'
|
||||
|
||||
export * from '#/state/queries/preferences/const'
|
||||
|
@ -33,6 +33,7 @@ const preferencesQueryKeyRoot = 'getPreferences'
|
|||
export const preferencesQueryKey = [preferencesQueryKeyRoot]
|
||||
|
||||
export function usePreferencesQuery() {
|
||||
const {getAgent} = useAgent()
|
||||
return useQuery({
|
||||
staleTime: STALE.SECONDS.FIFTEEN,
|
||||
structuralSharing: true,
|
||||
|
@ -118,6 +119,7 @@ export function useModerationOpts() {
|
|||
|
||||
export function useClearPreferencesMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async () => {
|
||||
|
@ -131,6 +133,7 @@ export function useClearPreferencesMutation() {
|
|||
}
|
||||
|
||||
export function usePreferencesSetContentLabelMutation() {
|
||||
const {getAgent} = useAgent()
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation<
|
||||
|
@ -150,6 +153,7 @@ export function usePreferencesSetContentLabelMutation() {
|
|||
|
||||
export function useSetContentLabelMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async ({
|
||||
|
@ -172,6 +176,7 @@ export function useSetContentLabelMutation() {
|
|||
|
||||
export function usePreferencesSetAdultContentMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
|
||||
return useMutation<void, unknown, {enabled: boolean}>({
|
||||
mutationFn: async ({enabled}) => {
|
||||
|
@ -186,6 +191,7 @@ export function usePreferencesSetAdultContentMutation() {
|
|||
|
||||
export function usePreferencesSetBirthDateMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
|
||||
return useMutation<void, unknown, {birthDate: Date}>({
|
||||
mutationFn: async ({birthDate}: {birthDate: Date}) => {
|
||||
|
@ -200,6 +206,7 @@ export function usePreferencesSetBirthDateMutation() {
|
|||
|
||||
export function useSetFeedViewPreferencesMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
|
||||
return useMutation<void, unknown, Partial<BskyFeedViewPreference>>({
|
||||
mutationFn: async prefs => {
|
||||
|
@ -214,6 +221,7 @@ export function useSetFeedViewPreferencesMutation() {
|
|||
|
||||
export function useSetThreadViewPreferencesMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
|
||||
return useMutation<void, unknown, Partial<ThreadViewPreferences>>({
|
||||
mutationFn: async prefs => {
|
||||
|
@ -228,6 +236,7 @@ export function useSetThreadViewPreferencesMutation() {
|
|||
|
||||
export function useSetSaveFeedsMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
|
||||
return useMutation<
|
||||
void,
|
||||
|
@ -246,6 +255,7 @@ export function useSetSaveFeedsMutation() {
|
|||
|
||||
export function useSaveFeedMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
|
||||
return useMutation<void, unknown, {uri: string}>({
|
||||
mutationFn: async ({uri}) => {
|
||||
|
@ -261,6 +271,7 @@ export function useSaveFeedMutation() {
|
|||
|
||||
export function useRemoveFeedMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
|
||||
return useMutation<void, unknown, {uri: string}>({
|
||||
mutationFn: async ({uri}) => {
|
||||
|
@ -276,6 +287,7 @@ export function useRemoveFeedMutation() {
|
|||
|
||||
export function usePinFeedMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
|
||||
return useMutation<void, unknown, {uri: string}>({
|
||||
mutationFn: async ({uri}) => {
|
||||
|
@ -291,6 +303,7 @@ export function usePinFeedMutation() {
|
|||
|
||||
export function useUnpinFeedMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
|
||||
return useMutation<void, unknown, {uri: string}>({
|
||||
mutationFn: async ({uri}) => {
|
||||
|
@ -306,6 +319,7 @@ export function useUnpinFeedMutation() {
|
|||
|
||||
export function useUpsertMutedWordsMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (mutedWords: AppBskyActorDefs.MutedWord[]) => {
|
||||
|
@ -320,6 +334,7 @@ export function useUpsertMutedWordsMutation() {
|
|||
|
||||
export function useUpdateMutedWordMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (mutedWord: AppBskyActorDefs.MutedWord) => {
|
||||
|
@ -334,6 +349,7 @@ export function useUpdateMutedWordMutation() {
|
|||
|
||||
export function useRemoveMutedWordMutation() {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async (mutedWord: AppBskyActorDefs.MutedWord) => {
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import {AppBskyFeedGetActorFeeds} from '@atproto/api'
|
||||
import {InfiniteData, QueryKey, useInfiniteQuery} from '@tanstack/react-query'
|
||||
|
||||
import {getAgent} from '#/state/session'
|
||||
import {useAgent} from '#/state/session'
|
||||
|
||||
const PAGE_SIZE = 30
|
||||
type RQPageParam = string | undefined
|
||||
|
@ -15,6 +15,7 @@ export function useProfileFeedgensQuery(
|
|||
opts?: {enabled?: boolean},
|
||||
) {
|
||||
const enabled = opts?.enabled !== false
|
||||
const {getAgent} = useAgent()
|
||||
return useInfiniteQuery<
|
||||
AppBskyFeedGetActorFeeds.OutputSchema,
|
||||
Error,
|
||||
|
|
|
@ -6,7 +6,7 @@ import {
|
|||
useInfiniteQuery,
|
||||
} from '@tanstack/react-query'
|
||||
|
||||
import {getAgent} from '#/state/session'
|
||||
import {useAgent} from '#/state/session'
|
||||
|
||||
const PAGE_SIZE = 30
|
||||
type RQPageParam = string | undefined
|
||||
|
@ -15,6 +15,7 @@ const RQKEY_ROOT = 'profile-followers'
|
|||
export const RQKEY = (did: string) => [RQKEY_ROOT, did]
|
||||
|
||||
export function useProfileFollowersQuery(did: string | undefined) {
|
||||
const {getAgent} = useAgent()
|
||||
return useInfiniteQuery<
|
||||
AppBskyGraphGetFollowers.OutputSchema,
|
||||
Error,
|
||||
|
|
|
@ -7,7 +7,7 @@ import {
|
|||
} from '@tanstack/react-query'
|
||||
|
||||
import {STALE} from '#/state/queries'
|
||||
import {getAgent} from '#/state/session'
|
||||
import {useAgent} from '#/state/session'
|
||||
|
||||
const PAGE_SIZE = 30
|
||||
type RQPageParam = string | undefined
|
||||
|
@ -17,6 +17,7 @@ const RQKEY_ROOT = 'profile-follows'
|
|||
export const RQKEY = (did: string) => [RQKEY_ROOT, did]
|
||||
|
||||
export function useProfileFollowsQuery(did: string | undefined) {
|
||||
const {getAgent} = useAgent()
|
||||
return useInfiniteQuery<
|
||||
AppBskyGraphGetFollows.OutputSchema,
|
||||
Error,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
import {AppBskyGraphGetLists} from '@atproto/api'
|
||||
import {InfiniteData, QueryKey, useInfiniteQuery} from '@tanstack/react-query'
|
||||
|
||||
import {getAgent} from '#/state/session'
|
||||
import {useAgent} from '#/state/session'
|
||||
|
||||
const PAGE_SIZE = 30
|
||||
type RQPageParam = string | undefined
|
||||
|
@ -11,6 +11,7 @@ export const RQKEY = (did: string) => [RQKEY_ROOT, did]
|
|||
|
||||
export function useProfileListsQuery(did: string, opts?: {enabled?: boolean}) {
|
||||
const enabled = opts?.enabled !== false
|
||||
const {getAgent} = useAgent()
|
||||
return useInfiniteQuery<
|
||||
AppBskyGraphGetLists.OutputSchema,
|
||||
Error,
|
||||
|
|
|
@ -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}) => {
|
||||
|
|
|
@ -2,7 +2,7 @@ import {AppBskyActorDefs, AtUri} from '@atproto/api'
|
|||
import {useQuery, useQueryClient, UseQueryResult} from '@tanstack/react-query'
|
||||
|
||||
import {STALE} from '#/state/queries'
|
||||
import {getAgent} from '#/state/session'
|
||||
import {useAgent} from '#/state/session'
|
||||
import {profileBasicQueryKey as RQKEY_PROFILE_BASIC} from './profile'
|
||||
|
||||
const RQKEY_ROOT = 'resolved-did'
|
||||
|
@ -24,6 +24,7 @@ export function useResolveUriQuery(uri: string | undefined): UriUseQueryResult {
|
|||
|
||||
export function useResolveDidQuery(didOrHandle: string | undefined) {
|
||||
const queryClient = useQueryClient()
|
||||
const {getAgent} = useAgent()
|
||||
|
||||
return useQuery<string, Error>({
|
||||
staleTime: STALE.HOURS.ONE,
|
||||
|
|
|
@ -6,7 +6,7 @@ import {
|
|||
useInfiniteQuery,
|
||||
} from '@tanstack/react-query'
|
||||
|
||||
import {getAgent} from '#/state/session'
|
||||
import {useAgent} from '#/state/session'
|
||||
import {embedViewRecordToPostView, getEmbeddedPost} from './util'
|
||||
|
||||
const searchPostsQueryKeyRoot = 'search-posts'
|
||||
|
@ -25,6 +25,7 @@ export function useSearchPostsQuery({
|
|||
sort?: 'top' | 'latest'
|
||||
enabled?: boolean
|
||||
}) {
|
||||
const {getAgent} = useAgent()
|
||||
return useInfiniteQuery<
|
||||
AppBskyFeedSearchPosts.OutputSchema,
|
||||
Error,
|
||||
|
|
|
@ -2,12 +2,13 @@ import {AppBskyFeedGetSuggestedFeeds} from '@atproto/api'
|
|||
import {InfiniteData, QueryKey, useInfiniteQuery} from '@tanstack/react-query'
|
||||
|
||||
import {STALE} from '#/state/queries'
|
||||
import {getAgent} from '#/state/session'
|
||||
import {useAgent} from '#/state/session'
|
||||
|
||||
const suggestedFeedsQueryKeyRoot = 'suggestedFeeds'
|
||||
export const suggestedFeedsQueryKey = [suggestedFeedsQueryKeyRoot]
|
||||
|
||||
export function useSuggestedFeedsQuery() {
|
||||
const {getAgent} = useAgent()
|
||||
return useInfiniteQuery<
|
||||
AppBskyFeedGetSuggestedFeeds.OutputSchema,
|
||||
Error,
|
||||
|
|
|
@ -14,7 +14,7 @@ import {
|
|||
|
||||
import {STALE} from '#/state/queries'
|
||||
import {useModerationOpts} from '#/state/queries/preferences'
|
||||
import {getAgent, useSession} from '#/state/session'
|
||||
import {useAgent, useSession} from '#/state/session'
|
||||
|
||||
const suggestedFollowsQueryKeyRoot = 'suggested-follows'
|
||||
const suggestedFollowsQueryKey = [suggestedFollowsQueryKeyRoot]
|
||||
|
@ -27,6 +27,7 @@ const suggestedFollowsByActorQueryKey = (did: string) => [
|
|||
|
||||
export function useSuggestedFollowsQuery() {
|
||||
const {currentAccount} = useSession()
|
||||
const {getAgent} = useAgent()
|
||||
const moderationOpts = useModerationOpts()
|
||||
|
||||
return useInfiniteQuery<
|
||||
|
@ -77,6 +78,7 @@ export function useSuggestedFollowsQuery() {
|
|||
}
|
||||
|
||||
export function useSuggestedFollowsByActorQuery({did}: {did: string}) {
|
||||
const {getAgent} = useAgent()
|
||||
return useQuery<AppBskyGraphGetSuggestedFollowsByActor.OutputSchema, Error>({
|
||||
queryKey: suggestedFollowsByActorQueryKey(did),
|
||||
queryFn: async () => {
|
||||
|
|
|
@ -23,16 +23,14 @@ import {readLabelers} from './agent-config'
|
|||
|
||||
let __globalAgent: BskyAgent = PUBLIC_BSKY_AGENT
|
||||
|
||||
/**
|
||||
* NOTE
|
||||
* Never hold on to the object returned by this function.
|
||||
* Call `getAgent()` at the time of invocation to ensure
|
||||
* that you never have a stale agent.
|
||||
*/
|
||||
export function getAgent() {
|
||||
function __getAgent() {
|
||||
return __globalAgent
|
||||
}
|
||||
|
||||
export function useAgent() {
|
||||
return React.useMemo(() => ({getAgent: __getAgent}), [])
|
||||
}
|
||||
|
||||
export type SessionAccount = persisted.PersistedAccount
|
||||
|
||||
export type SessionState = {
|
||||
|
|
|
@ -32,7 +32,7 @@ import {
|
|||
import {useProfileQuery} from '#/state/queries/profile'
|
||||
import {Gif} from '#/state/queries/tenor'
|
||||
import {ThreadgateSetting} from '#/state/queries/threadgate'
|
||||
import {getAgent, useSession} from '#/state/session'
|
||||
import {useAgent, useSession} from '#/state/session'
|
||||
import {useComposerControls} from '#/state/shell/composer'
|
||||
import {useAnalytics} from 'lib/analytics/analytics'
|
||||
import * as apilib from 'lib/api/index'
|
||||
|
@ -83,6 +83,7 @@ export const ComposePost = observer(function ComposePost({
|
|||
imageUris: initImageUris,
|
||||
}: Props) {
|
||||
const {currentAccount} = useSession()
|
||||
const {getAgent} = useAgent()
|
||||
const {data: currentProfile} = useProfileQuery({did: currentAccount!.did})
|
||||
const {isModalActive} = useModals()
|
||||
const {closeComposer} = useComposerControls()
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
import {useState, useEffect} from 'react'
|
||||
import {useEffect, useState} from 'react'
|
||||
|
||||
import {useAgent} from '#/state/session'
|
||||
import * as apilib from 'lib/api/index'
|
||||
import {getLinkMeta} from 'lib/link-meta/link-meta'
|
||||
import {ComposerOpts} from 'state/shell/composer'
|
||||
import {getAgent} from '#/state/session'
|
||||
|
||||
export function useExternalLinkFetch({}: {
|
||||
setQuote: (opts: ComposerOpts['quote']) => void
|
||||
}) {
|
||||
const {getAgent} = useAgent()
|
||||
const [extLink, setExtLink] = useState<apilib.ExternalEmbedDraft | undefined>(
|
||||
undefined,
|
||||
)
|
||||
|
@ -39,7 +41,7 @@ export function useExternalLinkFetch({}: {
|
|||
})
|
||||
}
|
||||
return cleanup
|
||||
}, [extLink])
|
||||
}, [extLink, getAgent])
|
||||
|
||||
return {extLink, setExtLink}
|
||||
}
|
||||
|
|
|
@ -1,24 +1,25 @@
|
|||
import {useState, useEffect} from 'react'
|
||||
import {ImageModel} from 'state/models/media/image'
|
||||
import {useEffect, useState} from 'react'
|
||||
|
||||
import {logger} from '#/logger'
|
||||
import {useFetchDid} from '#/state/queries/handle'
|
||||
import {useGetPost} from '#/state/queries/post'
|
||||
import {useAgent} from '#/state/session'
|
||||
import * as apilib from 'lib/api/index'
|
||||
import {getLinkMeta} from 'lib/link-meta/link-meta'
|
||||
import {POST_IMG_MAX} from 'lib/constants'
|
||||
import {
|
||||
getPostAsQuote,
|
||||
getFeedAsEmbed,
|
||||
getListAsEmbed,
|
||||
getPostAsQuote,
|
||||
} from 'lib/link-meta/bsky'
|
||||
import {getLinkMeta} from 'lib/link-meta/link-meta'
|
||||
import {downloadAndResize} from 'lib/media/manip'
|
||||
import {
|
||||
isBskyPostUrl,
|
||||
isBskyCustomFeedUrl,
|
||||
isBskyListUrl,
|
||||
isBskyPostUrl,
|
||||
} from 'lib/strings/url-helpers'
|
||||
import {ImageModel} from 'state/models/media/image'
|
||||
import {ComposerOpts} from 'state/shell/composer'
|
||||
import {POST_IMG_MAX} from 'lib/constants'
|
||||
import {logger} from '#/logger'
|
||||
import {getAgent} from '#/state/session'
|
||||
import {useGetPost} from '#/state/queries/post'
|
||||
import {useFetchDid} from '#/state/queries/handle'
|
||||
|
||||
export function useExternalLinkFetch({
|
||||
setQuote,
|
||||
|
@ -30,6 +31,7 @@ export function useExternalLinkFetch({
|
|||
)
|
||||
const getPost = useGetPost()
|
||||
const fetchDid = useFetchDid()
|
||||
const {getAgent} = useAgent()
|
||||
|
||||
useEffect(() => {
|
||||
let aborted = false
|
||||
|
@ -135,7 +137,7 @@ export function useExternalLinkFetch({
|
|||
})
|
||||
}
|
||||
return cleanup
|
||||
}, [extLink, setQuote, getPost, fetchDid])
|
||||
}, [extLink, setQuote, getPost, fetchDid, getAgent])
|
||||
|
||||
return {extLink, setExtLink}
|
||||
}
|
||||
|
|
|
@ -1,19 +1,20 @@
|
|||
import React, {useState} from 'react'
|
||||
import {ActivityIndicator, SafeAreaView, StyleSheet, View} from 'react-native'
|
||||
import {ScrollView, TextInput} from './util'
|
||||
import {Text} from '../util/text/Text'
|
||||
import {Button} from '../util/forms/Button'
|
||||
import {ErrorMessage} from '../util/error/ErrorMessage'
|
||||
import * as Toast from '../util/Toast'
|
||||
import {s, colors} from 'lib/styles'
|
||||
import {msg, Trans} from '@lingui/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
|
||||
import {useModalControls} from '#/state/modals'
|
||||
import {useAgent, useSession, useSessionApi} from '#/state/session'
|
||||
import {usePalette} from 'lib/hooks/usePalette'
|
||||
import {isWeb} from 'platform/detection'
|
||||
import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
|
||||
import {cleanError} from 'lib/strings/errors'
|
||||
import {Trans, msg} from '@lingui/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
import {useModalControls} from '#/state/modals'
|
||||
import {useSession, useSessionApi, getAgent} from '#/state/session'
|
||||
import {colors, s} from 'lib/styles'
|
||||
import {isWeb} from 'platform/detection'
|
||||
import {ErrorMessage} from '../util/error/ErrorMessage'
|
||||
import {Button} from '../util/forms/Button'
|
||||
import {Text} from '../util/text/Text'
|
||||
import * as Toast from '../util/Toast'
|
||||
import {ScrollView, TextInput} from './util'
|
||||
|
||||
enum Stages {
|
||||
InputEmail,
|
||||
|
@ -26,6 +27,7 @@ export const snapPoints = ['90%']
|
|||
export function Component() {
|
||||
const pal = usePalette('default')
|
||||
const {currentAccount} = useSession()
|
||||
const {getAgent} = useAgent()
|
||||
const {updateCurrentAccount} = useSessionApi()
|
||||
const {_} = useLingui()
|
||||
const [stage, setStage] = useState<Stages>(Stages.InputEmail)
|
||||
|
|
|
@ -16,8 +16,8 @@ import {useModalControls} from '#/state/modals'
|
|||
import {useFetchDid, useUpdateHandleMutation} from '#/state/queries/handle'
|
||||
import {useServiceQuery} from '#/state/queries/service'
|
||||
import {
|
||||
getAgent,
|
||||
SessionAccount,
|
||||
useAgent,
|
||||
useSession,
|
||||
useSessionApi,
|
||||
} from '#/state/session'
|
||||
|
@ -40,6 +40,7 @@ export type Props = {onChanged: () => void}
|
|||
|
||||
export function Component(props: Props) {
|
||||
const {currentAccount} = useSession()
|
||||
const {getAgent} = useAgent()
|
||||
const {
|
||||
isLoading,
|
||||
data: serviceInfo,
|
||||
|
|
|
@ -6,24 +6,25 @@ import {
|
|||
TouchableOpacity,
|
||||
View,
|
||||
} from 'react-native'
|
||||
import {ScrollView} from './util'
|
||||
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
|
||||
import {TextInput} from './util'
|
||||
import {Text} from '../util/text/Text'
|
||||
import {Button} from '../util/forms/Button'
|
||||
import {ErrorMessage} from '../util/error/ErrorMessage'
|
||||
import {s, colors} from 'lib/styles'
|
||||
import {msg, Trans} from '@lingui/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
import * as EmailValidator from 'email-validator'
|
||||
|
||||
import {logger} from '#/logger'
|
||||
import {useModalControls} from '#/state/modals'
|
||||
import {useAgent, useSession} from '#/state/session'
|
||||
import {usePalette} from 'lib/hooks/usePalette'
|
||||
import {isAndroid, isWeb} from 'platform/detection'
|
||||
import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
|
||||
import {cleanError, isNetworkError} from 'lib/strings/errors'
|
||||
import {checkAndFormatResetCode} from 'lib/strings/password'
|
||||
import {Trans, msg} from '@lingui/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
import {useModalControls} from '#/state/modals'
|
||||
import {useSession, getAgent} from '#/state/session'
|
||||
import * as EmailValidator from 'email-validator'
|
||||
import {logger} from '#/logger'
|
||||
import {colors, s} from 'lib/styles'
|
||||
import {isAndroid, isWeb} from 'platform/detection'
|
||||
import {ErrorMessage} from '../util/error/ErrorMessage'
|
||||
import {Button} from '../util/forms/Button'
|
||||
import {Text} from '../util/text/Text'
|
||||
import {ScrollView} from './util'
|
||||
import {TextInput} from './util'
|
||||
|
||||
enum Stages {
|
||||
RequestCode,
|
||||
|
@ -36,6 +37,7 @@ export const snapPoints = isAndroid ? ['90%'] : ['45%']
|
|||
export function Component() {
|
||||
const pal = usePalette('default')
|
||||
const {currentAccount} = useSession()
|
||||
const {getAgent} = useAgent()
|
||||
const {_} = useLingui()
|
||||
const [stage, setStage] = useState<Stages>(Stages.RequestCode)
|
||||
const [isProcessing, setIsProcessing] = useState<boolean>(false)
|
||||
|
|
|
@ -25,7 +25,7 @@ import {
|
|||
useListCreateMutation,
|
||||
useListMetadataMutation,
|
||||
} from '#/state/queries/list'
|
||||
import {getAgent} from '#/state/session'
|
||||
import {useAgent} from '#/state/session'
|
||||
import {useAnalytics} from 'lib/analytics/analytics'
|
||||
import {usePalette} from 'lib/hooks/usePalette'
|
||||
import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
|
||||
|
@ -62,6 +62,7 @@ export function Component({
|
|||
const {_} = useLingui()
|
||||
const listCreateMutation = useListCreateMutation()
|
||||
const listMetadataMutation = useListMetadataMutation()
|
||||
const {getAgent} = useAgent()
|
||||
|
||||
const activePurpose = useMemo(() => {
|
||||
if (list?.purpose) {
|
||||
|
@ -228,6 +229,7 @@ export function Component({
|
|||
listMetadataMutation,
|
||||
listCreateMutation,
|
||||
_,
|
||||
getAgent,
|
||||
])
|
||||
|
||||
return (
|
||||
|
|
|
@ -11,7 +11,7 @@ import {msg, Trans} from '@lingui/macro'
|
|||
import {useLingui} from '@lingui/react'
|
||||
|
||||
import {useModalControls} from '#/state/modals'
|
||||
import {getAgent, useSession, useSessionApi} from '#/state/session'
|
||||
import {useAgent, useSession, useSessionApi} from '#/state/session'
|
||||
import {usePalette} from 'lib/hooks/usePalette'
|
||||
import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
|
||||
import {cleanError} from 'lib/strings/errors'
|
||||
|
@ -30,6 +30,7 @@ export function Component({}: {}) {
|
|||
const pal = usePalette('default')
|
||||
const theme = useTheme()
|
||||
const {currentAccount} = useSession()
|
||||
const {getAgent} = useAgent()
|
||||
const {clearCurrentAccount, removeAccount} = useSessionApi()
|
||||
const {_} = useLingui()
|
||||
const {closeModal} = useModalControls()
|
||||
|
|
|
@ -13,7 +13,7 @@ import {useLingui} from '@lingui/react'
|
|||
|
||||
import {logger} from '#/logger'
|
||||
import {useModalControls} from '#/state/modals'
|
||||
import {getAgent, useSession, useSessionApi} from '#/state/session'
|
||||
import {useAgent, useSession, useSessionApi} from '#/state/session'
|
||||
import {usePalette} from 'lib/hooks/usePalette'
|
||||
import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
|
||||
import {cleanError} from 'lib/strings/errors'
|
||||
|
@ -41,6 +41,7 @@ export function Component({
|
|||
onSuccess?: () => void
|
||||
}) {
|
||||
const pal = usePalette('default')
|
||||
const {getAgent} = useAgent()
|
||||
const {currentAccount} = useSession()
|
||||
const {updateCurrentAccount} = useSessionApi()
|
||||
const {_} = useLingui()
|
||||
|
|
|
@ -19,7 +19,7 @@ import {resetProfilePostsQueries} from '#/state/queries/post-feed'
|
|||
import {useModerationOpts} from '#/state/queries/preferences'
|
||||
import {useProfileQuery} from '#/state/queries/profile'
|
||||
import {useResolveDidQuery} from '#/state/queries/resolve-uri'
|
||||
import {getAgent, useSession} from '#/state/session'
|
||||
import {useAgent, useSession} from '#/state/session'
|
||||
import {useSetDrawerSwipeDisabled, useSetMinimalShellMode} from '#/state/shell'
|
||||
import {useComposerControls} from '#/state/shell/composer'
|
||||
import {useAnalytics} from 'lib/analytics/analytics'
|
||||
|
@ -472,6 +472,7 @@ function ProfileScreenLoaded({
|
|||
}
|
||||
|
||||
function useRichText(text: string): [RichTextAPI, boolean] {
|
||||
const {getAgent} = useAgent()
|
||||
const [prevText, setPrevText] = React.useState(text)
|
||||
const [rawRT, setRawRT] = React.useState(() => new RichTextAPI({text}))
|
||||
const [resolvedRT, setResolvedRT] = React.useState<RichTextAPI | null>(null)
|
||||
|
@ -495,7 +496,7 @@ function useRichText(text: string): [RichTextAPI, boolean] {
|
|||
return () => {
|
||||
ignore = true
|
||||
}
|
||||
}, [text])
|
||||
}, [text, getAgent])
|
||||
const isResolving = resolvedRT === null
|
||||
return [resolvedRT ?? rawRT, isResolving]
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import {useLingui} from '@lingui/react'
|
|||
|
||||
import {cleanError} from '#/lib/strings/errors'
|
||||
import {isNative} from '#/platform/detection'
|
||||
import {getAgent, useSession, useSessionApi} from '#/state/session'
|
||||
import {useAgent, useSession, useSessionApi} from '#/state/session'
|
||||
import {ErrorMessage} from '#/view/com/util/error/ErrorMessage'
|
||||
import * as Toast from '#/view/com/util/Toast'
|
||||
import {atoms as a, useBreakpoints, useTheme} from '#/alf'
|
||||
|
@ -31,6 +31,7 @@ export function DisableEmail2FADialog({
|
|||
const {gtMobile} = useBreakpoints()
|
||||
const {currentAccount} = useSession()
|
||||
const {updateCurrentAccount} = useSessionApi()
|
||||
const {getAgent} = useAgent()
|
||||
|
||||
const [stage, setStage] = useState<Stages>(Stages.Email)
|
||||
const [confirmationCode, setConfirmationCode] = useState<string>('')
|
||||
|
|
|
@ -3,7 +3,7 @@ import {msg} from '@lingui/macro'
|
|||
import {useLingui} from '@lingui/react'
|
||||
|
||||
import {useModalControls} from '#/state/modals'
|
||||
import {getAgent, useSession, useSessionApi} from '#/state/session'
|
||||
import {useAgent, useSession, useSessionApi} from '#/state/session'
|
||||
import {ToggleButton} from 'view/com/util/forms/ToggleButton'
|
||||
import {useDialogControl} from '#/components/Dialog'
|
||||
import {DisableEmail2FADialog} from './DisableEmail2FADialog'
|
||||
|
@ -14,6 +14,7 @@ export function Email2FAToggle() {
|
|||
const {updateCurrentAccount} = useSessionApi()
|
||||
const {openModal} = useModalControls()
|
||||
const disableDialogCtrl = useDialogControl()
|
||||
const {getAgent} = useAgent()
|
||||
|
||||
const enableEmailAuthFactor = React.useCallback(async () => {
|
||||
if (currentAccount?.email) {
|
||||
|
@ -25,7 +26,7 @@ export function Email2FAToggle() {
|
|||
emailAuthFactor: true,
|
||||
})
|
||||
}
|
||||
}, [currentAccount, updateCurrentAccount])
|
||||
}, [currentAccount, updateCurrentAccount, getAgent])
|
||||
|
||||
const onToggle = React.useCallback(() => {
|
||||
if (!currentAccount) {
|
||||
|
|
|
@ -3,7 +3,7 @@ import {View} from 'react-native'
|
|||
import {msg, Trans} from '@lingui/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
|
||||
import {getAgent, useSession} from '#/state/session'
|
||||
import {useAgent, useSession} from '#/state/session'
|
||||
import {atoms as a, useBreakpoints, useTheme} from '#/alf'
|
||||
import {Button, ButtonText} from '#/components/Button'
|
||||
import * as Dialog from '#/components/Dialog'
|
||||
|
@ -19,6 +19,7 @@ export function ExportCarDialog({
|
|||
const t = useTheme()
|
||||
const {gtMobile} = useBreakpoints()
|
||||
const {currentAccount} = useSession()
|
||||
const {getAgent} = useAgent()
|
||||
|
||||
const downloadUrl = React.useMemo(() => {
|
||||
const agent = getAgent()
|
||||
|
@ -30,7 +31,7 @@ export function ExportCarDialog({
|
|||
url.pathname = '/xrpc/com.atproto.sync.getRepo'
|
||||
url.searchParams.set('did', agent.session.did)
|
||||
return url.toString()
|
||||
}, [currentAccount])
|
||||
}, [currentAccount, getAgent])
|
||||
|
||||
return (
|
||||
<Dialog.Outer control={control}>
|
||||
|
|
|
@ -13,7 +13,7 @@ import * as NavigationBar from 'expo-navigation-bar'
|
|||
import {StatusBar} from 'expo-status-bar'
|
||||
import {useNavigationState} from '@react-navigation/native'
|
||||
|
||||
import {getAgent, useSession} from '#/state/session'
|
||||
import {useAgent, useSession} from '#/state/session'
|
||||
import {
|
||||
useIsDrawerOpen,
|
||||
useIsDrawerSwipeDisabled,
|
||||
|
@ -57,6 +57,7 @@ function ShellInner() {
|
|||
)
|
||||
const canGoBack = useNavigationState(state => !isStateAtTabRoot(state))
|
||||
const {hasSession, currentAccount} = useSession()
|
||||
const {getAgent} = useAgent()
|
||||
const closeAnyActiveElement = useCloseAnyActiveElement()
|
||||
const {importantForAccessibility} = useDialogStateContext()
|
||||
// start undefined
|
||||
|
@ -85,7 +86,7 @@ function ShellInner() {
|
|||
)
|
||||
return unsub
|
||||
}
|
||||
}, [currentAccount])
|
||||
}, [currentAccount, getAgent])
|
||||
|
||||
return (
|
||||
<>
|
||||
|
|
Loading…
Reference in New Issue