Move the current agent to a global and reset RQ queries on agent change (#1946)
This commit is contained in:
parent
3043b32468
commit
357c752a21
40 changed files with 218 additions and 260 deletions
|
@ -56,7 +56,7 @@ import {
|
|||
useLanguagePrefsApi,
|
||||
toPostLanguages,
|
||||
} from '#/state/preferences/languages'
|
||||
import {useSession} from '#/state/session'
|
||||
import {useSession, getAgent} from '#/state/session'
|
||||
import {useProfileQuery} from '#/state/queries/profile'
|
||||
import {useComposerControls} from '#/state/shell/composer'
|
||||
|
||||
|
@ -67,7 +67,7 @@ export const ComposePost = observer(function ComposePost({
|
|||
quote: initQuote,
|
||||
mention: initMention,
|
||||
}: Props) {
|
||||
const {agent, currentAccount} = useSession()
|
||||
const {currentAccount} = useSession()
|
||||
const {data: currentProfile} = useProfileQuery({did: currentAccount!.did})
|
||||
const {activeModals} = useModals()
|
||||
const {openModal, closeModal} = useModalControls()
|
||||
|
@ -209,7 +209,7 @@ export const ComposePost = observer(function ComposePost({
|
|||
setIsProcessing(true)
|
||||
|
||||
try {
|
||||
await apilib.post(agent, {
|
||||
await apilib.post(getAgent(), {
|
||||
rawText: richtext.text,
|
||||
replyTo: replyTo?.uri,
|
||||
images: gallery.images,
|
||||
|
|
|
@ -16,7 +16,7 @@ import {
|
|||
import {ComposerOpts} from 'state/shell/composer'
|
||||
import {POST_IMG_MAX} from 'lib/constants'
|
||||
import {logger} from '#/logger'
|
||||
import {useSession} from '#/state/session'
|
||||
import {getAgent} from '#/state/session'
|
||||
import {useGetPost} from '#/state/queries/post'
|
||||
|
||||
export function useExternalLinkFetch({
|
||||
|
@ -24,7 +24,6 @@ export function useExternalLinkFetch({
|
|||
}: {
|
||||
setQuote: (opts: ComposerOpts['quote']) => void
|
||||
}) {
|
||||
const {agent} = useSession()
|
||||
const [extLink, setExtLink] = useState<apilib.ExternalEmbedDraft | undefined>(
|
||||
undefined,
|
||||
)
|
||||
|
@ -56,7 +55,7 @@ export function useExternalLinkFetch({
|
|||
},
|
||||
)
|
||||
} else if (isBskyCustomFeedUrl(extLink.uri)) {
|
||||
getFeedAsEmbed(agent, extLink.uri).then(
|
||||
getFeedAsEmbed(getAgent(), extLink.uri).then(
|
||||
({embed, meta}) => {
|
||||
if (aborted) {
|
||||
return
|
||||
|
@ -74,7 +73,7 @@ export function useExternalLinkFetch({
|
|||
},
|
||||
)
|
||||
} else if (isBskyListUrl(extLink.uri)) {
|
||||
getListAsEmbed(agent, extLink.uri).then(
|
||||
getListAsEmbed(getAgent(), extLink.uri).then(
|
||||
({embed, meta}) => {
|
||||
if (aborted) {
|
||||
return
|
||||
|
@ -92,7 +91,7 @@ export function useExternalLinkFetch({
|
|||
},
|
||||
)
|
||||
} else {
|
||||
getLinkMeta(agent, extLink.uri).then(meta => {
|
||||
getLinkMeta(getAgent(), extLink.uri).then(meta => {
|
||||
if (aborted) {
|
||||
return
|
||||
}
|
||||
|
@ -134,7 +133,7 @@ export function useExternalLinkFetch({
|
|||
})
|
||||
}
|
||||
return cleanup
|
||||
}, [agent, extLink, setQuote, getPost])
|
||||
}, [extLink, setQuote, getPost])
|
||||
|
||||
return {extLink, setExtLink}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ 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} from '#/state/session'
|
||||
import {useSession, useSessionApi, getAgent} from '#/state/session'
|
||||
|
||||
enum Stages {
|
||||
InputEmail,
|
||||
|
@ -25,7 +25,7 @@ export const snapPoints = ['90%']
|
|||
|
||||
export function Component() {
|
||||
const pal = usePalette('default')
|
||||
const {agent, currentAccount} = useSession()
|
||||
const {currentAccount} = useSession()
|
||||
const {updateCurrentAccount} = useSessionApi()
|
||||
const {_} = useLingui()
|
||||
const [stage, setStage] = useState<Stages>(Stages.InputEmail)
|
||||
|
@ -44,11 +44,11 @@ export function Component() {
|
|||
setError('')
|
||||
setIsProcessing(true)
|
||||
try {
|
||||
const res = await agent.com.atproto.server.requestEmailUpdate()
|
||||
const res = await getAgent().com.atproto.server.requestEmailUpdate()
|
||||
if (res.data.tokenRequired) {
|
||||
setStage(Stages.ConfirmCode)
|
||||
} else {
|
||||
await agent.com.atproto.server.updateEmail({email: email.trim()})
|
||||
await getAgent().com.atproto.server.updateEmail({email: email.trim()})
|
||||
updateCurrentAccount({
|
||||
email: email.trim(),
|
||||
emailConfirmed: false,
|
||||
|
@ -77,7 +77,7 @@ export function Component() {
|
|||
setError('')
|
||||
setIsProcessing(true)
|
||||
try {
|
||||
await agent.com.atproto.server.updateEmail({
|
||||
await getAgent().com.atproto.server.updateEmail({
|
||||
email: email.trim(),
|
||||
token: confirmationCode.trim(),
|
||||
})
|
||||
|
|
|
@ -26,19 +26,24 @@ import {useLingui} from '@lingui/react'
|
|||
import {useModalControls} from '#/state/modals'
|
||||
import {useServiceQuery} from '#/state/queries/service'
|
||||
import {useUpdateHandleMutation, useFetchDid} from '#/state/queries/handle'
|
||||
import {useSession, useSessionApi, SessionAccount} from '#/state/session'
|
||||
import {
|
||||
useSession,
|
||||
useSessionApi,
|
||||
SessionAccount,
|
||||
getAgent,
|
||||
} from '#/state/session'
|
||||
|
||||
export const snapPoints = ['100%']
|
||||
|
||||
export type Props = {onChanged: () => void}
|
||||
|
||||
export function Component(props: Props) {
|
||||
const {agent, currentAccount} = useSession()
|
||||
const {currentAccount} = useSession()
|
||||
const {
|
||||
isLoading,
|
||||
data: serviceInfo,
|
||||
error: serviceInfoError,
|
||||
} = useServiceQuery(agent.service.toString())
|
||||
} = useServiceQuery(getAgent().service.toString())
|
||||
|
||||
return isLoading || !currentAccount ? (
|
||||
<View style={{padding: 18}}>
|
||||
|
|
|
@ -19,14 +19,14 @@ import {resetToTab} from '../../../Navigation'
|
|||
import {Trans, msg} from '@lingui/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
import {useModalControls} from '#/state/modals'
|
||||
import {useSession, useSessionApi} from '#/state/session'
|
||||
import {useSession, useSessionApi, getAgent} from '#/state/session'
|
||||
|
||||
export const snapPoints = ['60%']
|
||||
|
||||
export function Component({}: {}) {
|
||||
const pal = usePalette('default')
|
||||
const theme = useTheme()
|
||||
const {agent, currentAccount} = useSession()
|
||||
const {currentAccount} = useSession()
|
||||
const {clearCurrentAccount, removeAccount} = useSessionApi()
|
||||
const {_} = useLingui()
|
||||
const {closeModal} = useModalControls()
|
||||
|
@ -40,7 +40,7 @@ export function Component({}: {}) {
|
|||
setError('')
|
||||
setIsProcessing(true)
|
||||
try {
|
||||
await agent.com.atproto.server.requestAccountDelete()
|
||||
await getAgent().com.atproto.server.requestAccountDelete()
|
||||
setIsEmailSent(true)
|
||||
} catch (e: any) {
|
||||
setError(cleanError(e))
|
||||
|
@ -57,7 +57,7 @@ export function Component({}: {}) {
|
|||
const token = confirmCode.replace(/\s/g, '')
|
||||
|
||||
try {
|
||||
await agent.com.atproto.server.deleteAccount({
|
||||
await getAgent().com.atproto.server.deleteAccount({
|
||||
did: currentAccount.did,
|
||||
password,
|
||||
token,
|
||||
|
|
|
@ -21,7 +21,7 @@ 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} from '#/state/session'
|
||||
import {useSession, useSessionApi, getAgent} from '#/state/session'
|
||||
|
||||
export const snapPoints = ['90%']
|
||||
|
||||
|
@ -33,7 +33,7 @@ enum Stages {
|
|||
|
||||
export function Component({showReminder}: {showReminder?: boolean}) {
|
||||
const pal = usePalette('default')
|
||||
const {agent, currentAccount} = useSession()
|
||||
const {currentAccount} = useSession()
|
||||
const {updateCurrentAccount} = useSessionApi()
|
||||
const {_} = useLingui()
|
||||
const [stage, setStage] = useState<Stages>(
|
||||
|
@ -49,7 +49,7 @@ export function Component({showReminder}: {showReminder?: boolean}) {
|
|||
setError('')
|
||||
setIsProcessing(true)
|
||||
try {
|
||||
await agent.com.atproto.server.requestEmailConfirmation()
|
||||
await getAgent().com.atproto.server.requestEmailConfirmation()
|
||||
setStage(Stages.ConfirmCode)
|
||||
} catch (e) {
|
||||
setError(cleanError(String(e)))
|
||||
|
@ -62,7 +62,7 @@ export function Component({showReminder}: {showReminder?: boolean}) {
|
|||
setError('')
|
||||
setIsProcessing(true)
|
||||
try {
|
||||
await agent.com.atproto.server.confirmEmail({
|
||||
await getAgent().com.atproto.server.confirmEmail({
|
||||
email: (currentAccount?.email || '').trim(),
|
||||
token: confirmationCode.trim(),
|
||||
})
|
||||
|
|
|
@ -16,7 +16,7 @@ import {CollectionId} from './types'
|
|||
import {Trans, msg} from '@lingui/macro'
|
||||
import {useLingui} from '@lingui/react'
|
||||
import {useModalControls} from '#/state/modals'
|
||||
import {useSession} from '#/state/session'
|
||||
import {getAgent} from '#/state/session'
|
||||
|
||||
const DMCA_LINK = 'https://blueskyweb.xyz/support/copyright'
|
||||
|
||||
|
@ -39,7 +39,6 @@ type ReportComponentProps =
|
|||
}
|
||||
|
||||
export function Component(content: ReportComponentProps) {
|
||||
const {agent} = useSession()
|
||||
const {closeModal} = useModalControls()
|
||||
const pal = usePalette('default')
|
||||
const {isMobile} = useWebMediaQueries()
|
||||
|
@ -70,7 +69,7 @@ export function Component(content: ReportComponentProps) {
|
|||
const $type = !isAccountReport
|
||||
? 'com.atproto.repo.strongRef'
|
||||
: 'com.atproto.admin.defs#repoRef'
|
||||
await agent.createModerationReport({
|
||||
await getAgent().createModerationReport({
|
||||
reasonType: issue,
|
||||
subject: {
|
||||
$type,
|
||||
|
|
|
@ -55,7 +55,12 @@ import {
|
|||
useRequireAltTextEnabled,
|
||||
useSetRequireAltTextEnabled,
|
||||
} from '#/state/preferences'
|
||||
import {useSession, useSessionApi, SessionAccount} from '#/state/session'
|
||||
import {
|
||||
useSession,
|
||||
useSessionApi,
|
||||
SessionAccount,
|
||||
getAgent,
|
||||
} from '#/state/session'
|
||||
import {useProfileQuery} from '#/state/queries/profile'
|
||||
import {useClearPreferencesMutation} from '#/state/queries/preferences'
|
||||
import {useInviteCodesQuery} from '#/state/queries/invites'
|
||||
|
@ -148,9 +153,11 @@ export const SettingsScreen = withAuthRequired(function Settings({}: Props) {
|
|||
const {isMobile} = useWebMediaQueries()
|
||||
const {screen, track} = useAnalytics()
|
||||
const {openModal} = useModalControls()
|
||||
const {isSwitchingAccounts, accounts, currentAccount, agent} = useSession()
|
||||
const {isSwitchingAccounts, accounts, currentAccount} = useSession()
|
||||
const {clearCurrentAccount} = useSessionApi()
|
||||
const [debugHeaderEnabled, toggleDebugHeader] = useDebugHeaderSetting(agent)
|
||||
const [debugHeaderEnabled, toggleDebugHeader] = useDebugHeaderSetting(
|
||||
getAgent(),
|
||||
)
|
||||
const {mutate: clearPreferences} = useClearPreferencesMutation()
|
||||
const {data: invites} = useInviteCodesQuery()
|
||||
const invitesAvailable = invites?.available?.length ?? 0
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue