Compare commits

...

1 Commits

Author SHA1 Message Date
Eric Bailey 3149f5234d Add back deprecated updateCurrentAccount and revert usages (#3540) 2024-04-13 13:40:53 -05:00
5 changed files with 30 additions and 8 deletions
+6
View File
@@ -371,6 +371,10 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
upsertAndPersistAccount,
])
const updateCurrentAccount = React.useCallback(async () => {
await refreshSession()
}, [refreshSession])
const selectAccount = React.useCallback<SessionApiContext['selectAccount']>(
async (account, logContext) => {
setIsSwitchingAccounts(true)
@@ -504,6 +508,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
selectAccount,
refreshSession,
clearCurrentAccount,
updateCurrentAccount,
}),
[
createAccount,
@@ -515,6 +520,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
selectAccount,
refreshSession,
clearCurrentAccount,
updateCurrentAccount,
],
)
+8
View File
@@ -77,4 +77,12 @@ export type SessionApiContext = {
* Refreshes the BskyAgent's session and derive a fresh `currentAccount`
*/
refreshSession: () => void
/**
* @deprecated Use `refreshSession` instead.
*/
updateCurrentAccount: (
account: Partial<
Pick<SessionAccount, 'handle' | 'email' | 'emailConfirmed'>
>,
) => void
}
+9 -3
View File
@@ -27,7 +27,7 @@ export const snapPoints = ['90%']
export function Component() {
const pal = usePalette('default')
const {currentAccount} = useSession()
const {refreshSession} = useSessionApi()
const {updateCurrentAccount} = useSessionApi()
const {_} = useLingui()
const [stage, setStage] = useState<Stages>(Stages.InputEmail)
const [email, setEmail] = useState<string>(currentAccount?.email || '')
@@ -50,7 +50,10 @@ export function Component() {
setStage(Stages.ConfirmCode)
} else {
await getAgent().com.atproto.server.updateEmail({email: email.trim()})
refreshSession()
updateCurrentAccount({
email: email.trim(),
emailConfirmed: false,
})
Toast.show(_(msg`Email updated`))
setStage(Stages.Done)
}
@@ -79,7 +82,10 @@ export function Component() {
email: email.trim(),
token: confirmationCode.trim(),
})
refreshSession()
updateCurrentAccount({
email: email.trim(),
emailConfirmed: false,
})
Toast.show(_(msg`Email updated`))
setStage(Stages.Done)
} catch (e) {
+5 -3
View File
@@ -72,7 +72,7 @@ export function Inner({
const {_} = useLingui()
const pal = usePalette('default')
const {track} = useAnalytics()
const {refreshSession} = useSessionApi()
const {updateCurrentAccount} = useSessionApi()
const {closeModal} = useModalControls()
const {mutateAsync: updateHandle, isPending: isUpdateHandlePending} =
useUpdateHandleMutation()
@@ -115,7 +115,9 @@ export function Inner({
await updateHandle({
handle: newHandle,
})
refreshSession()
updateCurrentAccount({
handle: newHandle,
})
closeModal()
onChanged()
} catch (err: any) {
@@ -131,7 +133,7 @@ export function Inner({
onChanged,
track,
closeModal,
refreshSession,
updateCurrentAccount,
updateHandle,
serviceInfo,
])
+2 -2
View File
@@ -36,7 +36,7 @@ enum Stages {
export function Component({showReminder}: {showReminder?: boolean}) {
const pal = usePalette('default')
const {currentAccount} = useSession()
const {refreshSession} = useSessionApi()
const {updateCurrentAccount} = useSessionApi()
const {_} = useLingui()
const [stage, setStage] = useState<Stages>(
showReminder ? Stages.Reminder : Stages.Email,
@@ -75,7 +75,7 @@ export function Component({showReminder}: {showReminder?: boolean}) {
email: (currentAccount?.email || '').trim(),
token: confirmationCode.trim(),
})
refreshSession()
updateCurrentAccount({emailConfirmed: true})
Toast.show(_(msg`Email verified`))
closeModal()
} catch (e) {