Bluesky app fork with some witchin' additions 馃挮
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at linkat-integration 44 lines 1.3 kB view raw
1import React from 'react' 2 3import * as persisted from '#/state/persisted' 4 5type StateContext = boolean 6type SetContext = (v: boolean) => void 7 8const stateContext = React.createContext<StateContext>( 9 Boolean(persisted.defaults.disableHaptics), 10) 11stateContext.displayName = 'DisableHapticsStateContext' 12const setContext = React.createContext<SetContext>((_: boolean) => {}) 13setContext.displayName = 'DisableHapticsSetContext' 14 15export function Provider({children}: {children: React.ReactNode}) { 16 const [state, setState] = React.useState( 17 Boolean(persisted.get('disableHaptics')), 18 ) 19 20 const setStateWrapped = React.useCallback( 21 (hapticsEnabled: persisted.Schema['disableHaptics']) => { 22 setState(Boolean(hapticsEnabled)) 23 persisted.write('disableHaptics', hapticsEnabled) 24 }, 25 [setState], 26 ) 27 28 React.useEffect(() => { 29 return persisted.onUpdate('disableHaptics', nextDisableHaptics => { 30 setState(Boolean(nextDisableHaptics)) 31 }) 32 }, [setStateWrapped]) 33 34 return ( 35 <stateContext.Provider value={state}> 36 <setContext.Provider value={setStateWrapped}> 37 {children} 38 </setContext.Provider> 39 </stateContext.Provider> 40 ) 41} 42 43export const useHapticsDisabled = () => React.useContext(stateContext) 44export const useSetHapticsDisabled = () => React.useContext(setContext)