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

Configure Feed

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

at 999e52ed2d5a2c8b2f7b8747dfcfd0e2017e5eb0 42 lines 1.2 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.repostCarouselEnabled), 10) 11const setContext = React.createContext<SetContext>((_: boolean) => {}) 12 13export function Provider({children}: {children: React.ReactNode}) { 14 const [state, setState] = React.useState( 15 Boolean(persisted.get('repostCarouselEnabled')), 16 ) 17 18 const setStateWrapped = React.useCallback( 19 (value: persisted.Schema['repostCarouselEnabled']) => { 20 setState(Boolean(value)) 21 persisted.write('repostCarouselEnabled', value) 22 }, 23 [setState], 24 ) 25 26 React.useEffect(() => { 27 return persisted.onUpdate('repostCarouselEnabled', nextValue => { 28 setState(Boolean(nextValue)) 29 }) 30 }, [setStateWrapped]) 31 32 return ( 33 <stateContext.Provider value={state}> 34 <setContext.Provider value={setStateWrapped}> 35 {children} 36 </setContext.Provider> 37 </stateContext.Provider> 38 ) 39} 40 41export const useRepostCarouselEnabled = () => React.useContext(stateContext) 42export const useSetRepostCarouselEnabled = () => React.useContext(setContext)