feat: Add pagination to product list endpoint and collection page#129
Open
Kavinayaboopathi wants to merge 1 commit intoNsanjayboruds:mainfrom
Open
feat: Add pagination to product list endpoint and collection page#129Kavinayaboopathi wants to merge 1 commit intoNsanjayboruds:mainfrom
Kavinayaboopathi wants to merge 1 commit intoNsanjayboruds:mainfrom
Conversation
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.
This PR introduces backend pagination for the product list endpoint and integrates minimal frontend support for fetching and displaying paginated products on the Collections page. This ensures better performance and faster frontend load times as the product count grows.
Changes Made
Backend
productController.js
: Updated
listProducts
to accept page, limit, and category query parameters.
Implemeted .skip() and .limit() database queries to fetch limited batches of products.
Returns paginated data (total, page, pages) alongside the products array.
Maintained backward compatibility: If the endpoint is hit without pagination parameters, it continues to return the default flat array of all products.
Frontend
ShopContext.jsx
: Added
getPaginatedProducts
helper function to construct queries and fetch the paginated endpoint.
Collections.jsx
:
Refactored the initial page load to fetch the first page from the backend.
Wired the "Load More Products" button to dynamically fetch sequential pages and append them to the UI list instead of triggering local dummy states.
Features a built-in fallback: If complex filters are selected on the UI, the frontend seamlessly transitions back into client-side array-based filtering.
Acceptance Criteria Supported
Backend responds to page, limit and category query params.
Valid pagination metadata (total, page, pages) is returned.
Zero-parameter API call remains backward compatible.
Frontend
Collections
page successfully consumes paginated states.