Bluesky app fork with some witchin' additions 💫
0
fork

Configure Feed

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

Fix notification invalidation condition on web (#2697)

Co-authored-by: Dan Abramov <dan@mac.home>

authored by

dan
Dan Abramov
and committed by
GitHub
7b683b61 59aacf41

+14 -7
+14 -7
src/view/screens/Notifications.tsx
··· 27 27 import {RQKEY as NOTIFS_RQKEY} from '#/state/queries/notifications/feed' 28 28 import {listenSoftReset, emitSoftReset} from '#/state/events' 29 29 import {truncateAndInvalidate} from '#/state/queries/util' 30 + import {useNonReactiveCallback} from '#/lib/hooks/useNonReactiveCallback' 30 31 import {isNative} from '#/platform/detection' 31 32 32 33 type Props = NativeStackScreenProps< ··· 38 39 const setMinimalShellMode = useSetMinimalShellMode() 39 40 const [isScrolledDown, setIsScrolledDown] = React.useState(false) 40 41 const scrollElRef = React.useRef<ListMethods>(null) 41 - const checkLatestRef = React.useRef<() => void | null>() 42 42 const {screen} = useAnalytics() 43 43 const pal = usePalette('default') 44 44 const {isDesktop} = useWebMediaQueries() ··· 66 66 } 67 67 }, [scrollToTop, queryClient, unreadApi, hasNew]) 68 68 69 - const onFocusCheckLatest = React.useCallback(() => { 69 + const onFocusCheckLatest = useNonReactiveCallback(() => { 70 70 // on focus, check for latest, but only invalidate if the user 71 71 // isnt scrolled down to avoid moving content underneath them 72 - unreadApi.checkUnread({invalidate: !isScrolledDown}) 73 - }, [unreadApi, isScrolledDown]) 74 - checkLatestRef.current = onFocusCheckLatest 72 + let currentIsScrolledDown 73 + if (isNative) { 74 + currentIsScrolledDown = isScrolledDown 75 + } else { 76 + // On the web, this isn't always updated in time so 77 + // we're just going to look it up synchronously. 78 + currentIsScrolledDown = window.scrollY > 200 79 + } 80 + unreadApi.checkUnread({invalidate: !currentIsScrolledDown}) 81 + }) 75 82 76 83 // on-visible setup 77 84 // = ··· 80 87 setMinimalShellMode(false) 81 88 logger.debug('NotificationsScreen: Focus') 82 89 screen('Notifications') 83 - checkLatestRef.current?.() 84 - }, [screen, setMinimalShellMode]), 90 + onFocusCheckLatest() 91 + }, [screen, setMinimalShellMode, onFocusCheckLatest]), 85 92 ) 86 93 React.useEffect(() => { 87 94 if (!isScreenFocused) {