From ece5b82e1a88867139982113c178361f836e6537 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Thu, 9 Nov 2023 10:32:13 -0600 Subject: [PATCH] Remove account --- src/state/session/index.tsx | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/state/session/index.tsx b/src/state/session/index.tsx index 194004dd4d..b295129b97 100644 --- a/src/state/session/index.tsx +++ b/src/state/session/index.tsx @@ -29,6 +29,7 @@ type ApiContext = { logout: () => Promise initSession: (account: Account) => Promise resumeSession: (account?: Account) => Promise + removeAccount: (account: Account) => void } export const PUBLIC_BSKY_AGENT = new BskyAgent({ @@ -48,6 +49,7 @@ const ApiContext = React.createContext({ logout: async () => {}, initSession: async () => {}, resumeSession: async () => {}, + removeAccount: () => {}, }) function createPersistSessionHandler( @@ -269,6 +271,18 @@ export function Provider({children}: React.PropsWithChildren<{}>) { [initSession], ) + const removeAccount = React.useCallback( + account => { + setStateWrapped(s => { + return { + ...s, + accounts: s.accounts.filter(a => a.did !== account.did), + } + }) + }, + [setStateWrapped], + ) + React.useEffect(() => { return persisted.onUpdate(() => { const session = persisted.get('session') @@ -301,9 +315,8 @@ export function Provider({children}: React.PropsWithChildren<{}>) { }) }, [state, logout, initSession]) - // TODO removeAccount - // TODO reloadFromServer - // TODO updateLocalAccountData + // TODO reloadFromServer, RQ? + // TODO updateLocalAccountData, RQ? const api = React.useMemo( () => ({ @@ -312,8 +325,9 @@ export function Provider({children}: React.PropsWithChildren<{}>) { logout, initSession, resumeSession, + removeAccount, }), - [createAccount, login, logout, initSession, resumeSession], + [createAccount, login, logout, initSession, resumeSession, removeAccount], ) return (