From c158ec103faf60b4a31a19b765c3835f5581c2f7 Mon Sep 17 00:00:00 2001 From: Zhou Yuhang <54398705+xquisite0@users.noreply.github.com> Date: Sun, 27 Jul 2025 09:12:48 +0800 Subject: [PATCH] [redditmon] inbox: load next page when last post in list is focused (#1576) --- .../src/components/posts/PostsContext.tsx | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/apps/redditmon/src/components/posts/PostsContext.tsx b/apps/redditmon/src/components/posts/PostsContext.tsx index 162d65399..c8b33c8ad 100644 --- a/apps/redditmon/src/components/posts/PostsContext.tsx +++ b/apps/redditmon/src/components/posts/PostsContext.tsx @@ -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) {