Skip to content

Commit

Permalink
Handle end of feed (#1898)
Browse files Browse the repository at this point in the history
* Handle end of feed

* Add isFetching
  • Loading branch information
estrattonbailey authored Nov 14, 2023
1 parent 4355f0f commit 3fde1be
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/view/screens/Feeds.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ export const FeedsScreen = withAuthRequired(function FeedsScreenImpl(
refetch: refetchPopularFeeds,
fetchNextPage: fetchNextPopularFeedsPage,
isFetchingNextPage: isPopularFeedsFetchingNextPage,
hasNextPage: hasNextPopularFeedsPage,
} = useGetPopularFeedsQuery()
const {_} = useLingui()
const setMinimalShellMode = useSetMinimalShellMode()
Expand Down Expand Up @@ -154,6 +155,22 @@ export const FeedsScreen = withAuthRequired(function FeedsScreenImpl(
await refetchPopularFeeds()
setIsPTR(false)
}, [setIsPTR, refetchPopularFeeds])
const onEndReached = React.useCallback(() => {
if (
isPopularFeedsFetching ||
isUserSearching ||
!hasNextPopularFeedsPage ||
popularFeedsError
)
return
fetchNextPopularFeedsPage()
}, [
isPopularFeedsFetching,
isUserSearching,
popularFeedsError,
hasNextPopularFeedsPage,
fetchNextPopularFeedsPage,
])

useFocusEffect(
React.useCallback(() => {
Expand Down Expand Up @@ -474,9 +491,7 @@ export const FeedsScreen = withAuthRequired(function FeedsScreenImpl(
/>
}
initialNumToRender={10}
onEndReached={() =>
isUserSearching ? undefined : fetchNextPopularFeedsPage()
}
onEndReached={onEndReached}
// @ts-ignore our .web version only -prf
desktopFixedHeight
/>
Expand Down

0 comments on commit 3fde1be

Please sign in to comment.