about summary refs log tree commit diff
path: root/src/state/shell/logged-out.tsx
blob: 19eaee76b7d55390f3fe59bbeab7374dea719444 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import React from 'react'

type StateContext = {
  showLoggedOut: boolean
}

const StateContext = React.createContext<StateContext>({
  showLoggedOut: false,
})
const ControlsContext = React.createContext<{
  setShowLoggedOut: (show: boolean) => void
}>({
  setShowLoggedOut: () => {},
})

export function Provider({children}: React.PropsWithChildren<{}>) {
  const [showLoggedOut, setShowLoggedOut] = React.useState(false)

  const state = React.useMemo(() => ({showLoggedOut}), [showLoggedOut])
  const controls = React.useMemo(() => ({setShowLoggedOut}), [setShowLoggedOut])

  return (
    <StateContext.Provider value={state}>
      <ControlsContext.Provider value={controls}>
        {children}
      </ControlsContext.Provider>
    </StateContext.Provider>
  )
}

export function useLoggedOutView() {
  return React.useContext(StateContext)
}

export function useLoggedOutViewControls() {
  return React.useContext(ControlsContext)
}