Skip to content

Commit 7ce9771

Browse files
Copilothpware
andcommitted
Add infinite scrolling with Load More button
Co-authored-by: hpware <157942818+hpware@users.noreply.github.com>
1 parent e11a38c commit 7ce9771

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

apps/web/src/components/publicPostsAndVideos.tsx

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ export function PublicPostsAndVideos({
235235
)}
236236
{status === "success" && data.pages?.[0]?.result !== undefined && (
237237
<div className="grid grid-cols-[repeat(auto-fill,minmax(280px,1fr))] gap-4">
238-
{(data.pages?.[0]?.result || []).map((i: Post) => (
238+
{data.pages.flatMap((page) => page.result || []).map((i: Post) => (
239239
<div
240240
className="border shadow text-wrap flex flex-col rounded m-1 dark:border-gray-100/50 p-2"
241241
key={crypto.randomUUID()}
@@ -311,6 +311,25 @@ export function PublicPostsAndVideos({
311311
))}
312312
</div>
313313
)}
314+
315+
{status === "success" && hasNextPage && (
316+
<div className="flex justify-center mt-6">
317+
<Button
318+
onClick={() => fetchNextPage()}
319+
disabled={isFetchingNextPage}
320+
variant="outline"
321+
>
322+
{isFetchingNextPage ? (
323+
<div className="flex items-center gap-2">
324+
<Spinner className="w-4 h-4" />
325+
<span>Loading more...</span>
326+
</div>
327+
) : (
328+
"Load More"
329+
)}
330+
</Button>
331+
</div>
332+
)}
314333

315334
{status === "error" ? (
316335
<div>

0 commit comments

Comments
 (0)