Remove global state manipulation in favor of refreshing the agent
This commit is contained in:
@@ -1,19 +1,20 @@
|
|||||||
import React, {useState} from 'react'
|
import React, {useState} from 'react'
|
||||||
import {ActivityIndicator, SafeAreaView, StyleSheet, View} from 'react-native'
|
import {ActivityIndicator, SafeAreaView, StyleSheet, View} from 'react-native'
|
||||||
import {ScrollView, TextInput} from './util'
|
import {msg, Trans} from '@lingui/macro'
|
||||||
import {Text} from '../util/text/Text'
|
import {useLingui} from '@lingui/react'
|
||||||
import {Button} from '../util/forms/Button'
|
|
||||||
import {ErrorMessage} from '../util/error/ErrorMessage'
|
import {useModalControls} from '#/state/modals'
|
||||||
import * as Toast from '../util/Toast'
|
import {getAgent, useSession, useSessionApi} from '#/state/session'
|
||||||
import {s, colors} from 'lib/styles'
|
|
||||||
import {usePalette} from 'lib/hooks/usePalette'
|
import {usePalette} from 'lib/hooks/usePalette'
|
||||||
import {isWeb} from 'platform/detection'
|
|
||||||
import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
|
import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
|
||||||
import {cleanError} from 'lib/strings/errors'
|
import {cleanError} from 'lib/strings/errors'
|
||||||
import {Trans, msg} from '@lingui/macro'
|
import {colors, s} from 'lib/styles'
|
||||||
import {useLingui} from '@lingui/react'
|
import {isWeb} from 'platform/detection'
|
||||||
import {useModalControls} from '#/state/modals'
|
import {ErrorMessage} from '../util/error/ErrorMessage'
|
||||||
import {useSession, useSessionApi, getAgent} from '#/state/session'
|
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 {
|
enum Stages {
|
||||||
InputEmail,
|
InputEmail,
|
||||||
@@ -26,7 +27,7 @@ export const snapPoints = ['90%']
|
|||||||
export function Component() {
|
export function Component() {
|
||||||
const pal = usePalette('default')
|
const pal = usePalette('default')
|
||||||
const {currentAccount} = useSession()
|
const {currentAccount} = useSession()
|
||||||
const {updateCurrentAccount} = useSessionApi()
|
const {refreshSession} = useSessionApi()
|
||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
const [stage, setStage] = useState<Stages>(Stages.InputEmail)
|
const [stage, setStage] = useState<Stages>(Stages.InputEmail)
|
||||||
const [email, setEmail] = useState<string>(currentAccount?.email || '')
|
const [email, setEmail] = useState<string>(currentAccount?.email || '')
|
||||||
@@ -49,10 +50,7 @@ export function Component() {
|
|||||||
setStage(Stages.ConfirmCode)
|
setStage(Stages.ConfirmCode)
|
||||||
} else {
|
} else {
|
||||||
await getAgent().com.atproto.server.updateEmail({email: email.trim()})
|
await getAgent().com.atproto.server.updateEmail({email: email.trim()})
|
||||||
updateCurrentAccount({
|
refreshSession()
|
||||||
email: email.trim(),
|
|
||||||
emailConfirmed: false,
|
|
||||||
})
|
|
||||||
Toast.show(_(msg`Email updated`))
|
Toast.show(_(msg`Email updated`))
|
||||||
setStage(Stages.Done)
|
setStage(Stages.Done)
|
||||||
}
|
}
|
||||||
@@ -81,10 +79,7 @@ export function Component() {
|
|||||||
email: email.trim(),
|
email: email.trim(),
|
||||||
token: confirmationCode.trim(),
|
token: confirmationCode.trim(),
|
||||||
})
|
})
|
||||||
updateCurrentAccount({
|
refreshSession()
|
||||||
email: email.trim(),
|
|
||||||
emailConfirmed: false,
|
|
||||||
})
|
|
||||||
Toast.show(_(msg`Email updated`))
|
Toast.show(_(msg`Email updated`))
|
||||||
setStage(Stages.Done)
|
setStage(Stages.Done)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ export function Inner({
|
|||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
const pal = usePalette('default')
|
const pal = usePalette('default')
|
||||||
const {track} = useAnalytics()
|
const {track} = useAnalytics()
|
||||||
const {updateCurrentAccount} = useSessionApi()
|
const {refreshSession} = useSessionApi()
|
||||||
const {closeModal} = useModalControls()
|
const {closeModal} = useModalControls()
|
||||||
const {mutateAsync: updateHandle, isPending: isUpdateHandlePending} =
|
const {mutateAsync: updateHandle, isPending: isUpdateHandlePending} =
|
||||||
useUpdateHandleMutation()
|
useUpdateHandleMutation()
|
||||||
@@ -115,9 +115,7 @@ export function Inner({
|
|||||||
await updateHandle({
|
await updateHandle({
|
||||||
handle: newHandle,
|
handle: newHandle,
|
||||||
})
|
})
|
||||||
updateCurrentAccount({
|
refreshSession()
|
||||||
handle: newHandle,
|
|
||||||
})
|
|
||||||
closeModal()
|
closeModal()
|
||||||
onChanged()
|
onChanged()
|
||||||
} catch (err: any) {
|
} catch (err: any) {
|
||||||
@@ -133,7 +131,7 @@ export function Inner({
|
|||||||
onChanged,
|
onChanged,
|
||||||
track,
|
track,
|
||||||
closeModal,
|
closeModal,
|
||||||
updateCurrentAccount,
|
refreshSession,
|
||||||
updateHandle,
|
updateHandle,
|
||||||
serviceInfo,
|
serviceInfo,
|
||||||
])
|
])
|
||||||
|
|||||||
@@ -6,23 +6,24 @@ import {
|
|||||||
StyleSheet,
|
StyleSheet,
|
||||||
View,
|
View,
|
||||||
} from 'react-native'
|
} from 'react-native'
|
||||||
import {Svg, Circle, Path} from 'react-native-svg'
|
import {Circle, Path, Svg} from 'react-native-svg'
|
||||||
import {ScrollView, TextInput} from './util'
|
|
||||||
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
|
import {FontAwesomeIcon} from '@fortawesome/react-native-fontawesome'
|
||||||
import {Text} from '../util/text/Text'
|
import {msg, Trans} from '@lingui/macro'
|
||||||
import {Button} from '../util/forms/Button'
|
import {useLingui} from '@lingui/react'
|
||||||
import {ErrorMessage} from '../util/error/ErrorMessage'
|
|
||||||
import * as Toast from '../util/Toast'
|
import {logger} from '#/logger'
|
||||||
import {s, colors} from 'lib/styles'
|
import {useModalControls} from '#/state/modals'
|
||||||
|
import {getAgent, useSession, useSessionApi} from '#/state/session'
|
||||||
import {usePalette} from 'lib/hooks/usePalette'
|
import {usePalette} from 'lib/hooks/usePalette'
|
||||||
import {isWeb} from 'platform/detection'
|
|
||||||
import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
|
import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
|
||||||
import {cleanError} from 'lib/strings/errors'
|
import {cleanError} from 'lib/strings/errors'
|
||||||
import {Trans, msg} from '@lingui/macro'
|
import {colors, s} from 'lib/styles'
|
||||||
import {useLingui} from '@lingui/react'
|
import {isWeb} from 'platform/detection'
|
||||||
import {useModalControls} from '#/state/modals'
|
import {ErrorMessage} from '../util/error/ErrorMessage'
|
||||||
import {useSession, useSessionApi, getAgent} from '#/state/session'
|
import {Button} from '../util/forms/Button'
|
||||||
import {logger} from '#/logger'
|
import {Text} from '../util/text/Text'
|
||||||
|
import * as Toast from '../util/Toast'
|
||||||
|
import {ScrollView, TextInput} from './util'
|
||||||
|
|
||||||
export const snapPoints = ['90%']
|
export const snapPoints = ['90%']
|
||||||
|
|
||||||
@@ -35,7 +36,7 @@ enum Stages {
|
|||||||
export function Component({showReminder}: {showReminder?: boolean}) {
|
export function Component({showReminder}: {showReminder?: boolean}) {
|
||||||
const pal = usePalette('default')
|
const pal = usePalette('default')
|
||||||
const {currentAccount} = useSession()
|
const {currentAccount} = useSession()
|
||||||
const {updateCurrentAccount} = useSessionApi()
|
const {refreshSession} = useSessionApi()
|
||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
const [stage, setStage] = useState<Stages>(
|
const [stage, setStage] = useState<Stages>(
|
||||||
showReminder ? Stages.Reminder : Stages.Email,
|
showReminder ? Stages.Reminder : Stages.Email,
|
||||||
@@ -74,7 +75,7 @@ export function Component({showReminder}: {showReminder?: boolean}) {
|
|||||||
email: (currentAccount?.email || '').trim(),
|
email: (currentAccount?.email || '').trim(),
|
||||||
token: confirmationCode.trim(),
|
token: confirmationCode.trim(),
|
||||||
})
|
})
|
||||||
updateCurrentAccount({emailConfirmed: true})
|
refreshSession()
|
||||||
Toast.show(_(msg`Email verified`))
|
Toast.show(_(msg`Email verified`))
|
||||||
closeModal()
|
closeModal()
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user