about summary refs log tree commit diff
path: root/src/state/shell
diff options
context:
space:
mode:
Diffstat (limited to 'src/state/shell')
-rw-r--r--src/state/shell/logged-out.tsx70
1 files changed, 62 insertions, 8 deletions
diff --git a/src/state/shell/logged-out.tsx b/src/state/shell/logged-out.tsx
index 19eaee76b..a06a6d969 100644
--- a/src/state/shell/logged-out.tsx
+++ b/src/state/shell/logged-out.tsx
@@ -1,23 +1,77 @@
 import React from 'react'
 
-type StateContext = {
+type State = {
   showLoggedOut: boolean
+  /**
+   * Account did used to populate the login form when the logged out view is
+   * shown.
+   */
+  requestedAccountSwitchTo?: string
 }
 
-const StateContext = React.createContext<StateContext>({
+type Controls = {
+  /**
+   * Show or hide the logged out view.
+   */
+  setShowLoggedOut: (show: boolean) => void
+  /**
+   * Shows the logged out view and drops the user into the login form using the
+   * requested account.
+   */
+  requestSwitchToAccount: (props: {
+    /**
+     * The did of the account to populate the login form with.
+     */
+    requestedAccount?: string
+  }) => void
+  /**
+   * Clears the requested account so that next time the logged out view is
+   * show, no account is pre-populated.
+   */
+  clearRequestedAccount: () => void
+}
+
+const StateContext = React.createContext<State>({
   showLoggedOut: false,
+  requestedAccountSwitchTo: undefined,
 })
-const ControlsContext = React.createContext<{
-  setShowLoggedOut: (show: boolean) => void
-}>({
+
+const ControlsContext = React.createContext<Controls>({
   setShowLoggedOut: () => {},
+  requestSwitchToAccount: () => {},
+  clearRequestedAccount: () => {},
 })
 
 export function Provider({children}: React.PropsWithChildren<{}>) {
-  const [showLoggedOut, setShowLoggedOut] = React.useState(false)
+  const [state, setState] = React.useState<State>({
+    showLoggedOut: false,
+    requestedAccountSwitchTo: undefined,
+  })
 
-  const state = React.useMemo(() => ({showLoggedOut}), [showLoggedOut])
-  const controls = React.useMemo(() => ({setShowLoggedOut}), [setShowLoggedOut])
+  const controls = React.useMemo<Controls>(
+    () => ({
+      setShowLoggedOut(show) {
+        setState(s => ({
+          ...s,
+          showLoggedOut: show,
+        }))
+      },
+      requestSwitchToAccount({requestedAccount}) {
+        setState(s => ({
+          ...s,
+          showLoggedOut: true,
+          requestedAccountSwitchTo: requestedAccount,
+        }))
+      },
+      clearRequestedAccount() {
+        setState(s => ({
+          ...s,
+          requestedAccountSwitchTo: undefined,
+        }))
+      },
+    }),
+    [setState],
+  )
 
   return (
     <StateContext.Provider value={state}>