[redditmon] inbox: load next page when last post in list is focused (#1576)

This commit is contained in:
Zhou Yuhang 2025-07-27 09:12:48 +08:00 committed by GitHub
parent ba87956839
commit c158ec103f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 19 additions and 0 deletions

View File

@ -169,6 +169,25 @@ export function PostsProvider({
}
}, [params?.id]);
// Auto-load next page when user reaches the last post
useEffect(() => {
if (
selectedPostId &&
posts.length > 0 &&
hasNextPage &&
!isFetchingNextPage
) {
const currentPostIndex = posts.findIndex(
(post) => post.id === selectedPostId,
);
// If user is on the last post in the current list, auto-load more
if (currentPostIndex === posts.length - 1) {
fetchNextPage();
}
}
}, [selectedPostId, hasNextPage, isFetchingNextPage, fetchNextPage, posts]);
// Calculate adjacent posts
const adjacentPosts = useMemo(() => {
if (!selectedPostId || !posts.length) {