Skip to content

Commit

Permalink
Remove account
Browse files Browse the repository at this point in the history
  • Loading branch information
estrattonbailey committed Nov 9, 2023
1 parent 7ee624e commit ece5b82
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions src/state/session/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type ApiContext = {
logout: () => Promise<void>
initSession: (account: Account) => Promise<void>
resumeSession: (account?: Account) => Promise<void>
removeAccount: (account: Account) => void
}

export const PUBLIC_BSKY_AGENT = new BskyAgent({
Expand All @@ -48,6 +49,7 @@ const ApiContext = React.createContext<ApiContext>({
logout: async () => {},
initSession: async () => {},
resumeSession: async () => {},
removeAccount: () => {},
})

function createPersistSessionHandler(
Expand Down Expand Up @@ -269,6 +271,18 @@ export function Provider({children}: React.PropsWithChildren<{}>) {
[initSession],
)

const removeAccount = React.useCallback<ApiContext['removeAccount']>(
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')
Expand Down Expand Up @@ -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(
() => ({
Expand All @@ -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 (
Expand Down

0 comments on commit ece5b82

Please sign in to comment.