about summary refs log tree commit diff
path: root/src/view/shell/desktop/LeftNav.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/desktop/LeftNav.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/desktop/LeftNav.tsx')
-rw-r--r--src/view/shell/desktop/LeftNav.tsx11
1 files changed, 10 insertions, 1 deletions
diff --git a/src/view/shell/desktop/LeftNav.tsx b/src/view/shell/desktop/LeftNav.tsx
index 841a49d38..8f6998abf 100644
--- a/src/view/shell/desktop/LeftNav.tsx
+++ b/src/view/shell/desktop/LeftNav.tsx
@@ -45,6 +45,8 @@ import {useUnreadNotifications} from '#/state/queries/notifications/unread'
 import {useComposerControls} from '#/state/shell/composer'
 import {useFetchHandle} from '#/state/queries/handle'
 import {emitSoftReset} from '#/state/events'
+import {useQueryClient} from '@tanstack/react-query'
+import {RQKEY as NOTIFS_RQKEY} from '#/state/queries/notifications/feed'
 
 function ProfileCard() {
   const {currentAccount} = useSession()
@@ -118,6 +120,7 @@ interface NavItemProps {
 }
 function NavItem({count, href, icon, iconFilled, label}: NavItemProps) {
   const pal = usePalette('default')
+  const queryClient = useQueryClient()
   const {currentAccount} = useSession()
   const {isDesktop, isTablet} = useWebMediaQueries()
   const [pathName] = React.useMemo(() => router.matchPath(href), [href])
@@ -143,10 +146,16 @@ function NavItem({count, href, icon, iconFilled, label}: NavItemProps) {
       if (isCurrent) {
         emitSoftReset()
       } else {
+        if (href === '/notifications') {
+          // fetch new notifs on view
+          queryClient.invalidateQueries({
+            queryKey: NOTIFS_RQKEY(),
+          })
+        }
         onPress()
       }
     },
-    [onPress, isCurrent],
+    [onPress, isCurrent, queryClient, href],
   )
 
   return (