about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authordan <dan.abramov@gmail.com>2024-01-31 02:52:20 +0000
committerGitHub <noreply@github.com>2024-01-30 18:52:20 -0800
commit7b683b617a410a38830933b57c38b9fa74f4a4c1 (patch)
tree69c45ea17d3ced8627dba12680c5720889a8aab3 /src
parent59aacf4126c3b9ffead339960b082bcc415b1766 (diff)
downloadvoidsky-7b683b617a410a38830933b57c38b9fa74f4a4c1.tar.zst
Fix notification invalidation condition on web (#2697)
Co-authored-by: Dan Abramov <dan@mac.home>
Diffstat (limited to 'src')
-rw-r--r--src/view/screens/Notifications.tsx21
1 files changed, 14 insertions, 7 deletions
diff --git a/src/view/screens/Notifications.tsx b/src/view/screens/Notifications.tsx
index 6e2f18305..03f0a8f61 100644
--- a/src/view/screens/Notifications.tsx
+++ b/src/view/screens/Notifications.tsx
@@ -27,6 +27,7 @@ import {
 import {RQKEY as NOTIFS_RQKEY} from '#/state/queries/notifications/feed'
 import {listenSoftReset, emitSoftReset} from '#/state/events'
 import {truncateAndInvalidate} from '#/state/queries/util'
+import {useNonReactiveCallback} from '#/lib/hooks/useNonReactiveCallback'
 import {isNative} from '#/platform/detection'
 
 type Props = NativeStackScreenProps<
@@ -38,7 +39,6 @@ export function NotificationsScreen({}: Props) {
   const setMinimalShellMode = useSetMinimalShellMode()
   const [isScrolledDown, setIsScrolledDown] = React.useState(false)
   const scrollElRef = React.useRef<ListMethods>(null)
-  const checkLatestRef = React.useRef<() => void | null>()
   const {screen} = useAnalytics()
   const pal = usePalette('default')
   const {isDesktop} = useWebMediaQueries()
@@ -66,12 +66,19 @@ export function NotificationsScreen({}: Props) {
     }
   }, [scrollToTop, queryClient, unreadApi, hasNew])
 
-  const onFocusCheckLatest = React.useCallback(() => {
+  const onFocusCheckLatest = useNonReactiveCallback(() => {
     // on focus, check for latest, but only invalidate if the user
     // isnt scrolled down to avoid moving content underneath them
-    unreadApi.checkUnread({invalidate: !isScrolledDown})
-  }, [unreadApi, isScrolledDown])
-  checkLatestRef.current = onFocusCheckLatest
+    let currentIsScrolledDown
+    if (isNative) {
+      currentIsScrolledDown = isScrolledDown
+    } else {
+      // On the web, this isn't always updated in time so
+      // we're just going to look it up synchronously.
+      currentIsScrolledDown = window.scrollY > 200
+    }
+    unreadApi.checkUnread({invalidate: !currentIsScrolledDown})
+  })
 
   // on-visible setup
   // =
@@ -80,8 +87,8 @@ export function NotificationsScreen({}: Props) {
       setMinimalShellMode(false)
       logger.debug('NotificationsScreen: Focus')
       screen('Notifications')
-      checkLatestRef.current?.()
-    }, [screen, setMinimalShellMode]),
+      onFocusCheckLatest()
+    }, [screen, setMinimalShellMode, onFocusCheckLatest]),
   )
   React.useEffect(() => {
     if (!isScreenFocused) {