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 54 lines 1.5 kB view raw
1import React from 'react' 2 3import * as persisted from '#/state/persisted' 4 5type StateContext = persisted.Schema['showExternalShareButtons'] 6type SetContext = (v: persisted.Schema['showExternalShareButtons']) => void 7 8const stateContext = React.createContext<StateContext>( 9 persisted.defaults.showExternalShareButtons, 10) 11const setContext = React.createContext<SetContext>( 12 (_: persisted.Schema['showExternalShareButtons']) => {}, 13) 14 15export function Provider({children}: React.PropsWithChildren<{}>) { 16 const [state, setState] = React.useState( 17 persisted.get('showExternalShareButtons'), 18 ) 19 20 const setStateWrapped = React.useCallback( 21 ( 22 showExternalShareButtons: persisted.Schema['showExternalShareButtons'], 23 ) => { 24 setState(showExternalShareButtons) 25 persisted.write('showExternalShareButtons', showExternalShareButtons) 26 }, 27 [setState], 28 ) 29 30 React.useEffect(() => { 31 return persisted.onUpdate( 32 'showExternalShareButtons', 33 nextShowExternalShareButtons => { 34 setState(nextShowExternalShareButtons) 35 }, 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 function useShowExternalShareButtons() { 49 return React.useContext(stateContext) 50} 51 52export function useSetShowExternalShareButtons() { 53 return React.useContext(setContext) 54}