Bluesky app fork with some witchin' additions 💫
0
fork

Configure Feed

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

style: remove `useUnreadCountLabel` hack from `50c1841` (#655) (#686)

I just realized how `mobx` works (never used before lol) and now I feel
dumb.

authored by

LW and committed by
GitHub
41f3a055 656baa72

+9 -25
+3 -4
src/Navigation.tsx
··· 28 28 import {useColorSchemeStyle} from 'lib/hooks/useColorSchemeStyle' 29 29 import {router} from './routes' 30 30 import {usePalette} from 'lib/hooks/usePalette' 31 - import {useUnreadCountLabel} from 'lib/hooks/useUnreadCountLabel' 32 31 import {useStores} from './state' 33 32 34 33 import {HomeScreen} from './view/screens/Home' ··· 296 295 * The FlatNavigator is used by Web to represent the routes 297 296 * in a single ("flat") stack. 298 297 */ 299 - function FlatNavigator() { 298 + const FlatNavigator = observer(() => { 300 299 const pal = usePalette('default') 301 - const unreadCountLabel = useUnreadCountLabel() 300 + const unreadCountLabel = useStores().me.notifications.unreadCountLabel 302 301 const title = (page: string) => bskyTitle(page, unreadCountLabel) 303 302 return ( 304 303 <Flat.Navigator ··· 327 326 {commonScreens(Flat as typeof HomeTab, unreadCountLabel)} 328 327 </Flat.Navigator> 329 328 ) 330 - } 329 + }) 331 330 332 331 /** 333 332 * The RoutesContainer should wrap all components which need access
+6 -2
src/lib/hooks/useSetTitle.ts
··· 3 3 4 4 import {NavigationProp} from 'lib/routes/types' 5 5 import {bskyTitle} from 'lib/strings/headings' 6 - import {useUnreadCountLabel} from './useUnreadCountLabel' 6 + import {useStores} from 'state/index' 7 7 8 + /** 9 + * Requires consuming component to be wrapped in `observer`: 10 + * https://stackoverflow.com/a/71488009 11 + */ 8 12 export function useSetTitle(title?: string) { 9 13 const navigation = useNavigation<NavigationProp>() 10 - const unreadCountLabel = useUnreadCountLabel() 14 + const {unreadCountLabel} = useStores().me.notifications 11 15 useEffect(() => { 12 16 if (title) { 13 17 navigation.setOptions({title: bskyTitle(title, unreadCountLabel)})
-19
src/lib/hooks/useUnreadCountLabel.ts
··· 1 - import {useEffect, useReducer} from 'react' 2 - import {DeviceEventEmitter} from 'react-native' 3 - import {useStores} from 'state/index' 4 - 5 - export function useUnreadCountLabel() { 6 - // HACK: We don't have anything like Redux selectors, 7 - // and we don't want to use <RootStoreContext.Consumer /> 8 - // to react to the whole store 9 - const [, forceUpdate] = useReducer(x => x + 1, 0) 10 - useEffect(() => { 11 - const subscription = DeviceEventEmitter.addListener( 12 - 'unread-notifications', 13 - forceUpdate, 14 - ) 15 - return () => subscription?.remove() 16 - }, [forceUpdate]) 17 - 18 - return useStores().me.notifications.unreadCountLabel 19 - }