about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorPaul Frazee <pfrazee@gmail.com>2023-04-24 19:41:27 -0500
committerGitHub <noreply@github.com>2023-04-24 19:41:27 -0500
commitf4da2f444281c8b8f693833d727fc7c7bc85f8ae (patch)
treebe4b25dc98f170d6b3d3faec326240e8e8574b71 /src
parent7a1076271600814629d52b8a1d6eb02b968c947f (diff)
downloadvoidsky-f4da2f444281c8b8f693833d727fc7c7bc85f8ae.tar.zst
Tune feed loading behavior (#528)
* Never autoload home feed on focus

* On web, just check for new notifications on focus

* Switching tab in the home feed now checks for latest
Diffstat (limited to 'src')
-rw-r--r--src/view/screens/Home.tsx27
-rw-r--r--src/view/screens/Notifications.tsx11
2 files changed, 21 insertions, 17 deletions
diff --git a/src/view/screens/Home.tsx b/src/view/screens/Home.tsx
index d1677e548..53bef813d 100644
--- a/src/view/screens/Home.tsx
+++ b/src/view/screens/Home.tsx
@@ -149,6 +149,8 @@ const FeedPage = observer(
       }
     }, [isPageFocused, scrollToTop, feed])
 
+    // fires when screen is activated/deactivated
+    // - set up polls/listeners, update content
     useFocusEffect(
       React.useCallback(() => {
         const softResetSub = store.onScreenSoftReset(onSoftReset)
@@ -168,30 +170,27 @@ const FeedPage = observer(
         }
       }, [store, doPoll, onSoftReset, screen, feed]),
     )
+    // fires when tab is actived/deactivated
+    // - check for latest
     useTabFocusEffect(
       'Home',
       React.useCallback(
         isInside => {
-          if (!isPageFocused) {
+          if (!isPageFocused || !isInside) {
             return
           }
-          // on mobile:
-          // fires with `isInside=true` when the user navigates to the root tab
-          // but not when the user goes back to the screen by pressing back
-          // on web:
-          // essentially equivalent to useFocusEffect because we dont used tabbed
-          // navigation
-          if (isInside) {
-            if (feed.hasNewLatest) {
-              feed.refresh()
-            } else {
-              feed.checkForLatest()
-            }
-          }
+          feed.checkForLatest()
         },
         [isPageFocused, feed],
       ),
     )
+    // fires when page within screen is activated/deactivated
+    // - check for latest
+    React.useEffect(() => {
+      if (isPageFocused && isScreenFocused) {
+        feed.checkForLatest()
+      }
+    }, [isPageFocused, isScreenFocused, feed])
 
     const onPressCompose = React.useCallback(() => {
       track('HomeScreen:PressCompose')
diff --git a/src/view/screens/Notifications.tsx b/src/view/screens/Notifications.tsx
index d93666aa8..8d6f7c83a 100644
--- a/src/view/screens/Notifications.tsx
+++ b/src/view/screens/Notifications.tsx
@@ -16,6 +16,7 @@ import {useOnMainScroll} from 'lib/hooks/useOnMainScroll'
 import {useTabFocusEffect} from 'lib/hooks/useTabFocusEffect'
 import {s} from 'lib/styles'
 import {useAnalytics} from 'lib/analytics'
+import {isWeb} from 'platform/detection'
 
 type Props = NativeStackScreenProps<
   NotificationsTabNavigatorParams,
@@ -70,10 +71,14 @@ export const NotificationsScreen = withAuthRequired(
           // essentially equivalent to useFocusEffect because we dont used tabbed
           // navigation
           if (isInside) {
-            if (store.me.notifications.unreadCount > 0) {
-              store.me.notifications.refresh()
-            } else {
+            if (isWeb) {
               store.me.notifications.syncQueue()
+            } else {
+              if (store.me.notifications.unreadCount > 0) {
+                store.me.notifications.refresh()
+              } else {
+                store.me.notifications.syncQueue()
+              }
             }
           }
         },