Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Review Summary by QodoAdd pagination helpers and comprehensive documentation
WalkthroughsDescription• Add four pagination helper functions for TMDB paginated responses • Implement paginate() async generator for lazy page iteration • Implement fetchAllPages() to collect all pages with deduplication support • Implement hasNextPage() and hasPreviousPage() for UI navigation checks • Implement getPageInfo() to extract structured pagination metadata • Add comprehensive test suite with 22 unit tests covering edge cases • Add detailed pagination guide with runnable examples and best practices Diagramflowchart LR
A["PaginatedResponse<T>"] -->|"paginate()"| B["AsyncGenerator<br/>lazy iteration"]
A -->|"fetchAllPages()"| C["T[] flat array<br/>with deduplication"]
A -->|"hasNextPage()<br/>hasPreviousPage()"| D["boolean<br/>UI checks"]
A -->|"getPageInfo()"| E["PageInfo<br/>structured metadata"]
B --> F["Early exit<br/>checkpoint resume"]
C --> G["maxPages cap<br/>deduplicateBy key"]
E --> H["React pagination<br/>infinite scroll"]
File Changes1. packages/tmdb/src/utils/pagination.ts
|
Code Review by Qodo
1.
|
Add pagination utilities
Introduces four standalone helper functions for working with paginated TMDB responses, exported from the main package entry point.
New helpers (
utils/pagination.ts)paginate(fetcher, startPage?)— async generator that lazily yields onePaginatedResponse<T>at a time. Supports earlybreakand resuming from a checkpoint viastartPage.fetchAllPages(fetcher, options?)— collects all pages into a flatT[]. AcceptsmaxPages(defaults to TMDB's hard cap of 500) anddeduplicateByto handle cross-page duplicates caused by live popularity re-ranking on endpoints likenow_playing.hasNextPage(response)/hasPreviousPage(response)— boolean checks for UI navigation; accept minimalPicktypes so they work with any paginated response shape.getPageInfo(response)— returns structured metadata{ current, total, totalResults, isFirst, isLast }for driving pagination controls.Tests
22 unit tests covering all helpers, including edge cases: empty results, early generator exit,
startPage,maxPagesenforcement, the 500-page TMDB cap, deduplication key collision behaviour, and the no-deduplication default.Docs
New Pagination guide covering all four helpers with runnable examples: lazy iteration, DB batch sync, checkpoint resuming, React pagination buttons, infinite scroll sentinel, and the cross-page duplicate caveat with mitigation.