Bluesky app fork with some witchin' additions 馃挮 witchsky.app
bluesky fork client
119
fork

Configure Feed

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

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