about summary refs log tree commit diff
path: root/src/view/shell/bottom-bar/BottomBar.tsx
diff options
context:
space:
mode:
authorPaul Frazee <pfrazee@gmail.com>2023-11-16 18:27:05 -0800
committerGitHub <noreply@github.com>2023-11-16 18:27:05 -0800
commite358c3cc3045c70ed2d187c022aca185674c8274 (patch)
tree2aafe711b830910364a7f3aab474a0ffe55f681f /src/view/shell/bottom-bar/BottomBar.tsx
parent357c752a213dbcf77e5333fa180cfef20a33842d (diff)
downloadvoidsky-e358c3cc3045c70ed2d187c022aca185674c8274.tar.zst
Improve notification load behaviors (#1943)
* Dont use the stale cache for notifs-feed

* Add a delay to marking all read to avoid marking upcoming posts as read

* Trigger automatic notifications refresh when navigating to the tab, in certain conditions
Diffstat (limited to 'src/view/shell/bottom-bar/BottomBar.tsx')
-rw-r--r--src/view/shell/bottom-bar/BottomBar.tsx11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/view/shell/bottom-bar/BottomBar.tsx b/src/view/shell/bottom-bar/BottomBar.tsx
index ed800679d..6935953b5 100644
--- a/src/view/shell/bottom-bar/BottomBar.tsx
+++ b/src/view/shell/bottom-bar/BottomBar.tsx
@@ -1,6 +1,7 @@
 import React, {ComponentProps} from 'react'
 import {GestureResponderEvent, TouchableOpacity, View} from 'react-native'
 import Animated from 'react-native-reanimated'
+import {useQueryClient} from '@tanstack/react-query'
 import {StackActions} from '@react-navigation/native'
 import {BottomTabBarProps} from '@react-navigation/bottom-tabs'
 import {useSafeAreaInsets} from 'react-native-safe-area-context'
@@ -30,6 +31,7 @@ import {useUnreadNotifications} from '#/state/queries/notifications/unread'
 import {emitSoftReset} from '#/state/events'
 import {useSession} from '#/state/session'
 import {useProfileQuery} from '#/state/queries/profile'
+import {RQKEY as NOTIFS_RQKEY} from '#/state/queries/notifications/feed'
 
 type TabOptions = 'Home' | 'Search' | 'Notifications' | 'MyProfile' | 'Feeds'
 
@@ -38,6 +40,7 @@ export function BottomBar({navigation}: BottomTabBarProps) {
   const {currentAccount} = useSession()
   const pal = usePalette('default')
   const {_} = useLingui()
+  const queryClient = useQueryClient()
   const safeAreaInsets = useSafeAreaInsets()
   const {track} = useAnalytics()
   const {footerHeight} = useShellLayout()
@@ -57,10 +60,16 @@ export function BottomBar({navigation}: BottomTabBarProps) {
       } else if (tabState === TabState.Inside) {
         navigation.dispatch(StackActions.popToTop())
       } else {
+        if (tab === 'Notifications') {
+          // fetch new notifs on view
+          queryClient.invalidateQueries({
+            queryKey: NOTIFS_RQKEY(),
+          })
+        }
         navigation.navigate(`${tab}Tab`)
       }
     },
-    [track, navigation],
+    [track, navigation, queryClient],
   )
   const onPressHome = React.useCallback(() => onPressTab('Home'), [onPressTab])
   const onPressSearch = React.useCallback(