Add back deprecated updateCurrentAccount and revert usages

This commit is contained in:
Eric Bailey
2024-04-13 13:23:03 -05:00
parent 73fec7fb3c
commit 98a3aa9c7f
5 changed files with 30 additions and 8 deletions
+6
View File
@@ -371,6 +371,10 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
upsertAndPersistAccount, upsertAndPersistAccount,
]) ])
const updateCurrentAccount = React.useCallback(async () => {
await refreshSession()
}, [refreshSession])
const selectAccount = React.useCallback<SessionApiContext['selectAccount']>( const selectAccount = React.useCallback<SessionApiContext['selectAccount']>(
async (account, logContext) => { async (account, logContext) => {
setIsSwitchingAccounts(true) setIsSwitchingAccounts(true)
@@ -504,6 +508,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
selectAccount, selectAccount,
refreshSession, refreshSession,
clearCurrentAccount, clearCurrentAccount,
updateCurrentAccount,
}), }),
[ [
createAccount, createAccount,
@@ -515,6 +520,7 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
selectAccount, selectAccount,
refreshSession, refreshSession,
clearCurrentAccount, clearCurrentAccount,
updateCurrentAccount,
], ],
) )
+8
View File
@@ -77,4 +77,12 @@ export type SessionApiContext = {
* Refreshes the BskyAgent's session and derive a fresh `currentAccount` * Refreshes the BskyAgent's session and derive a fresh `currentAccount`
*/ */
refreshSession: () => void 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() { export function Component() {
const pal = usePalette('default') const pal = usePalette('default')
const {currentAccount} = useSession() const {currentAccount} = useSession()
const {refreshSession} = useSessionApi() const {updateCurrentAccount} = 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 || '')
@@ -50,7 +50,10 @@ 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()})
refreshSession() updateCurrentAccount({
email: email.trim(),
emailConfirmed: false,
})
Toast.show(_(msg`Email updated`)) Toast.show(_(msg`Email updated`))
setStage(Stages.Done) setStage(Stages.Done)
} }
@@ -79,7 +82,10 @@ export function Component() {
email: email.trim(), email: email.trim(),
token: confirmationCode.trim(), token: confirmationCode.trim(),
}) })
refreshSession() updateCurrentAccount({
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) {
+5 -3
View File
@@ -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 {refreshSession} = useSessionApi() const {updateCurrentAccount} = useSessionApi()
const {closeModal} = useModalControls() const {closeModal} = useModalControls()
const {mutateAsync: updateHandle, isPending: isUpdateHandlePending} = const {mutateAsync: updateHandle, isPending: isUpdateHandlePending} =
useUpdateHandleMutation() useUpdateHandleMutation()
@@ -115,7 +115,9 @@ export function Inner({
await updateHandle({ await updateHandle({
handle: newHandle, handle: newHandle,
}) })
refreshSession() updateCurrentAccount({
handle: newHandle,
})
closeModal() closeModal()
onChanged() onChanged()
} catch (err: any) { } catch (err: any) {
@@ -131,7 +133,7 @@ export function Inner({
onChanged, onChanged,
track, track,
closeModal, closeModal,
refreshSession, updateCurrentAccount,
updateHandle, updateHandle,
serviceInfo, serviceInfo,
]) ])
+2 -2
View File
@@ -36,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 {refreshSession} = useSessionApi() const {updateCurrentAccount} = 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,
@@ -75,7 +75,7 @@ export function Component({showReminder}: {showReminder?: boolean}) {
email: (currentAccount?.email || '').trim(), email: (currentAccount?.email || '').trim(),
token: confirmationCode.trim(), token: confirmationCode.trim(),
}) })
refreshSession() updateCurrentAccount({emailConfirmed: true})
Toast.show(_(msg`Email verified`)) Toast.show(_(msg`Email verified`))
closeModal() closeModal()
} catch (e) { } catch (e) {