about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorPaul Frazee <pfrazee@gmail.com>2023-12-27 08:53:24 -0800
committerGitHub <noreply@github.com>2023-12-27 08:53:24 -0800
commite1ba649560b9bb619dd445520ed9ea867f78ed4d (patch)
tree5378ced9ff6d236c15a0a02fa4609653296dfbc3 /src
parent8b6ecf6bfff0a18e92a172004cd37fe2aacaf37f (diff)
downloadvoidsky-e1ba649560b9bb619dd445520ed9ea867f78ed4d.tar.zst
Fixes to feed load triggers (#2323)
* Add soft-reset support to ProfileFeed and ProfileList

* Fix: correctly unsubscribe the notifications soft-reset listener
Diffstat (limited to 'src')
-rw-r--r--src/view/screens/Notifications.tsx8
-rw-r--r--src/view/screens/ProfileFeed.tsx9
-rw-r--r--src/view/screens/ProfileList.tsx9
3 files changed, 24 insertions, 2 deletions
diff --git a/src/view/screens/Notifications.tsx b/src/view/screens/Notifications.tsx
index e28a67e37..6e2f18305 100644
--- a/src/view/screens/Notifications.tsx
+++ b/src/view/screens/Notifications.tsx
@@ -1,6 +1,6 @@
 import React from 'react'
 import {View} from 'react-native'
-import {useFocusEffect} from '@react-navigation/native'
+import {useFocusEffect, useIsFocused} from '@react-navigation/native'
 import {useQueryClient} from '@tanstack/react-query'
 import {
   NativeStackScreenProps,
@@ -46,6 +46,7 @@ export function NotificationsScreen({}: Props) {
   const unreadNotifs = useUnreadNotifications()
   const unreadApi = useUnreadNotificationsApi()
   const hasNew = !!unreadNotifs
+  const isScreenFocused = useIsFocused()
 
   // event handlers
   // =
@@ -83,8 +84,11 @@ export function NotificationsScreen({}: Props) {
     }, [screen, setMinimalShellMode]),
   )
   React.useEffect(() => {
+    if (!isScreenFocused) {
+      return
+    }
     return listenSoftReset(onPressLoadLatest)
-  }, [onPressLoadLatest])
+  }, [onPressLoadLatest, isScreenFocused])
 
   const ListHeaderComponent = React.useCallback(() => {
     if (isDesktop) {
diff --git a/src/view/screens/ProfileFeed.tsx b/src/view/screens/ProfileFeed.tsx
index cde39a33f..211306c0d 100644
--- a/src/view/screens/ProfileFeed.tsx
+++ b/src/view/screens/ProfileFeed.tsx
@@ -57,6 +57,7 @@ import {useLikeMutation, useUnlikeMutation} from '#/state/queries/like'
 import {useComposerControls} from '#/state/shell/composer'
 import {truncateAndInvalidate} from '#/state/queries/util'
 import {isNative} from '#/platform/detection'
+import {listenSoftReset} from '#/state/events'
 
 const SECTION_TITLES = ['Posts', 'About']
 
@@ -446,6 +447,7 @@ const FeedSection = React.forwardRef<SectionRef, FeedSectionProps>(
     const [hasNew, setHasNew] = React.useState(false)
     const [isScrolledDown, setIsScrolledDown] = React.useState(false)
     const queryClient = useQueryClient()
+    const isScreenFocused = useIsFocused()
 
     const onScrollToTop = useCallback(() => {
       scrollElRef.current?.scrollToOffset({
@@ -460,6 +462,13 @@ const FeedSection = React.forwardRef<SectionRef, FeedSectionProps>(
       scrollToTop: onScrollToTop,
     }))
 
+    React.useEffect(() => {
+      if (!isScreenFocused) {
+        return
+      }
+      return listenSoftReset(onScrollToTop)
+    }, [onScrollToTop, isScreenFocused])
+
     const renderPostsEmpty = useCallback(() => {
       return <EmptyState icon="feed" message="This feed is empty!" />
     }, [])
diff --git a/src/view/screens/ProfileList.tsx b/src/view/screens/ProfileList.tsx
index 2db768cc5..c51758ae5 100644
--- a/src/view/screens/ProfileList.tsx
+++ b/src/view/screens/ProfileList.tsx
@@ -57,6 +57,7 @@ import {
 } from '#/state/queries/preferences'
 import {logger} from '#/logger'
 import {useAnalytics} from '#/lib/analytics/analytics'
+import {listenSoftReset} from '#/state/events'
 
 const SECTION_TITLES_CURATE = ['Posts', 'About']
 const SECTION_TITLES_MOD = ['About']
@@ -601,6 +602,7 @@ const FeedSection = React.forwardRef<SectionRef, FeedSectionProps>(
     const queryClient = useQueryClient()
     const [hasNew, setHasNew] = React.useState(false)
     const [isScrolledDown, setIsScrolledDown] = React.useState(false)
+    const isScreenFocused = useIsFocused()
 
     const onScrollToTop = useCallback(() => {
       scrollElRef.current?.scrollToOffset({
@@ -614,6 +616,13 @@ const FeedSection = React.forwardRef<SectionRef, FeedSectionProps>(
       scrollToTop: onScrollToTop,
     }))
 
+    React.useEffect(() => {
+      if (!isScreenFocused) {
+        return
+      }
+      return listenSoftReset(onScrollToTop)
+    }, [onScrollToTop, isScreenFocused])
+
     const renderPostsEmpty = useCallback(() => {
       return <EmptyState icon="feed" message="This feed is empty!" />
     }, [])