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

Configure Feed

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

at theme-changes 49 lines 1.4 kB view raw
1import { 2 createContext, 3 useCallback, 4 useContext, 5 useEffect, 6 useState, 7} from 'react' 8import type {PropsWithChildren} from 'react' 9 10import * as persisted from '#/state/persisted' 11 12type StateContext = boolean 13type SetContext = (v: boolean) => void 14 15const stateContext = createContext<StateContext>( 16 Boolean(persisted.defaults.disableAutoplay), 17) 18stateContext.displayName = 'AutoplayStateContext' 19const setContext = createContext<SetContext>((_: boolean) => {}) 20setContext.displayName = 'AutoplaySetContext' 21 22export function Provider({children}: PropsWithChildren<{}>) { 23 const [state, setState] = useState(Boolean(persisted.get('disableAutoplay'))) 24 25 const setStateWrapped = useCallback( 26 (autoplayDisabled: persisted.Schema['disableAutoplay']) => { 27 setState(Boolean(autoplayDisabled)) 28 persisted.write('disableAutoplay', autoplayDisabled) 29 }, 30 [setState], 31 ) 32 33 useEffect(() => { 34 return persisted.onUpdate('disableAutoplay', nextDisableAutoplay => { 35 setState(Boolean(nextDisableAutoplay)) 36 }) 37 }, [setStateWrapped]) 38 39 return ( 40 <stateContext.Provider value={state}> 41 <setContext.Provider value={setStateWrapped}> 42 {children} 43 </setContext.Provider> 44 </stateContext.Provider> 45 ) 46} 47 48export const useAutoplayDisabled = () => useContext(stateContext) 49export const useSetAutoplayDisabled = () => useContext(setContext)