Handle end of feed (#1898)

* Handle end of feed

* Add isFetching
zio/stable
Eric Bailey 2023-11-14 11:28:40 -06:00 committed by GitHub
parent 4355f0fd9a
commit 3fde1bea1b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 3 deletions

View File

@ -107,6 +107,7 @@ export const FeedsScreen = withAuthRequired(function FeedsScreenImpl(
refetch: refetchPopularFeeds,
fetchNextPage: fetchNextPopularFeedsPage,
isFetchingNextPage: isPopularFeedsFetchingNextPage,
hasNextPage: hasNextPopularFeedsPage,
} = useGetPopularFeedsQuery()
const {_} = useLingui()
const setMinimalShellMode = useSetMinimalShellMode()
@ -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(() => {
@ -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
/>