Feature: pagination controls#1
Merged
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Pull request overview
Adds server-backed pagination controls to the postcard listing so the home page no longer needs to load/render the entire dataset at once, and exposes counts to support filter tabs with totals.
Changes:
- Introduce
PostcardFilter/PostcardCountstypes for filter/count plumbing. - Home page now loads an initial page (default 21) plus grouped status counts and passes them to the client.
/api/postcardsGET now supportspage/pageSize(and returnscounts+pagination) and the home client uses it for filter/page navigation and refresh after actions.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| package.json | Bumps app version to reflect the new feature. |
| lib/types.ts | Adds shared types for filters and count maps used by API + UI. |
| app/page.tsx | Loads initial paginated results + initial counts and passes new props to the client. |
| app/home-client.tsx | Implements pagination UI, server-driven filtering, and reload-after-mutations. |
| app/api/postcards/route.ts | Adds paginated GET query support and returns counts/pagination metadata. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
8
to
10
| // GET /api/postcards -> all postcards (newest first) | ||
| // GET /api/postcards?status=available | ||
| // GET /api/postcards?mine=1 -> postcards claimed by the current user |
Comment on lines
+23
to
+25
| const page = positiveInt(searchParams.get("page"), 1); | ||
| const pageSize = Math.min(100, positiveInt(searchParams.get("pageSize"), 21)); | ||
| const offset = (page - 1) * pageSize; |
| "use client"; | ||
|
|
||
| import { useMemo, useState } from "react"; | ||
| import { useEffect, useMemo, useState } from "react"; |
Comment on lines
+48
to
+50
| const [pageSize, setPageSize] = useState(initialPageSize); | ||
| const [page, setPage] = useState(1); | ||
| const [loadingPage, setLoadingPage] = useState(false); |
Comment on lines
+102
to
+107
|
|
||
| setFilter(nextFilter); | ||
| setPageSize(nextPageSize); | ||
| setPage(safePage); | ||
| setCounts(nextCounts); | ||
| setPostcards(data.postcards || []); |
Comment on lines
+110
to
+112
| } finally { | ||
| setLoadingPage(false); | ||
| } |
Comment on lines
+293
to
+300
| onChange={(e) => { | ||
| const next = Number(e.target.value); | ||
| if (!Number.isFinite(next)) return; | ||
| loadPage({ | ||
| nextPage: 1, | ||
| nextPageSize: Math.min(100, Math.max(1, Math.floor(next))), | ||
| }); | ||
| }} |
Comment on lines
+76
to
+78
| setLoadingPage(true); | ||
| setError(null); | ||
| try { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.