about summary refs log tree commit diff
path: root/src/view/screens/Notifications.tsx
diff options
context:
space:
mode:
authorPaul Frazee <pfrazee@gmail.com>2023-12-09 15:09:31 -0800
committerGitHub <noreply@github.com>2023-12-09 15:09:31 -0800
commit6b3eb401b04ee442005a9690dcf90e16d46c35e0 (patch)
tree536ed44b8b7f436e4144573dedef8d41c7cb3801 /src/view/screens/Notifications.tsx
parentd854e882187c4358ae3b4c1fb9d1324f5fe215e4 (diff)
downloadvoidsky-6b3eb401b04ee442005a9690dcf90e16d46c35e0.tar.zst
Multiple notifications fixes (#2154)
* Dont reset notifications feed on push notification event

* Dont separate notifications by read state to avoid jank

* On notifications screen focus, check latest and only rerender if not scrolled down

* Reuse the cached notifs page when its not stale

* Bump ios build number

* Improve comments

* Change the 'mark all read' condition to avoid firing too early
Diffstat (limited to 'src/view/screens/Notifications.tsx')
-rw-r--r--src/view/screens/Notifications.tsx17
1 files changed, 14 insertions, 3 deletions
diff --git a/src/view/screens/Notifications.tsx b/src/view/screens/Notifications.tsx
index 0af6484f3..fceaa60c2 100644
--- a/src/view/screens/Notifications.tsx
+++ b/src/view/screens/Notifications.tsx
@@ -37,6 +37,7 @@ export function NotificationsScreen({}: Props) {
   const setMinimalShellMode = useSetMinimalShellMode()
   const [onMainScroll, isScrolledDown, resetMainScroll] = useOnMainScroll()
   const scrollElRef = React.useRef<FlatList>(null)
+  const checkLatestRef = React.useRef<() => void | null>()
   const {screen} = useAnalytics()
   const pal = usePalette('default')
   const {isDesktop} = useWebMediaQueries()
@@ -63,16 +64,26 @@ export function NotificationsScreen({}: Props) {
     }
   }, [scrollToTop, queryClient, unreadApi, hasNew])
 
+  const onFocusCheckLatest = React.useCallback(() => {
+    // 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
+
   // on-visible setup
   // =
   useFocusEffect(
     React.useCallback(() => {
       setMinimalShellMode(false)
-      logger.debug('NotificationsScreen: Updating feed')
+      logger.debug('NotificationsScreen: Focus')
       screen('Notifications')
-      return listenSoftReset(onPressLoadLatest)
-    }, [screen, onPressLoadLatest, setMinimalShellMode]),
+      checkLatestRef.current?.()
+    }, [screen, setMinimalShellMode]),
   )
+  React.useEffect(() => {
+    return listenSoftReset(onPressLoadLatest)
+  }, [onPressLoadLatest])
 
   const ListHeaderComponent = React.useCallback(() => {
     if (isDesktop) {