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
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue