forked from
jollywhoppers.com/witchsky.app
Bluesky app fork with some witchin' additions 馃挮
1import {createContext, useContext, useState} from 'react'
2
3import {useHotkeysContext} from '#/lib/hotkeys'
4
5type StateContext = boolean
6type SetContext = (v: boolean) => void
7
8const stateContext = createContext<StateContext>(false)
9stateContext.displayName = 'DrawerOpenStateContext'
10const setContext = createContext<SetContext>((_: boolean) => {})
11setContext.displayName = 'DrawerOpenSetContext'
12
13export function Provider({children}: React.PropsWithChildren<{}>) {
14 const [state, setState] = useState(false)
15 const {disableScope, enableScope} = useHotkeysContext()
16
17 const setDrawerOpen = (open: boolean) => {
18 if (open) {
19 disableScope('global')
20 } else {
21 enableScope('global')
22 }
23 setState(open)
24 }
25
26 return (
27 <stateContext.Provider value={state}>
28 <setContext.Provider value={setDrawerOpen}>
29 {children}
30 </setContext.Provider>
31 </stateContext.Provider>
32 )
33}
34
35export function useIsDrawerOpen() {
36 return useContext(stateContext)
37}
38
39export function useSetDrawerOpen() {
40 return useContext(setContext)
41}