Skip to content

Commit

Permalink
Fixes to feed load triggers (#2323)
Browse files Browse the repository at this point in the history
* Add soft-reset support to ProfileFeed and ProfileList

* Fix: correctly unsubscribe the notifications soft-reset listener
  • Loading branch information
pfrazee authored Dec 27, 2023
1 parent 8b6ecf6 commit e1ba649
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/view/screens/Notifications.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -46,6 +46,7 @@ export function NotificationsScreen({}: Props) {
const unreadNotifs = useUnreadNotifications()
const unreadApi = useUnreadNotificationsApi()
const hasNew = !!unreadNotifs
const isScreenFocused = useIsFocused()

// event handlers
// =
Expand Down Expand Up @@ -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) {
Expand Down
9 changes: 9 additions & 0 deletions src/view/screens/ProfileFeed.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Expand Down Expand Up @@ -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({
Expand All @@ -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!" />
}, [])
Expand Down
9 changes: 9 additions & 0 deletions src/view/screens/ProfileList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand Down Expand Up @@ -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({
Expand All @@ -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!" />
}, [])
Expand Down

0 comments on commit e1ba649

Please sign in to comment.