add task solution#1485
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Your implementation has critical issues that violate task requirements. The onPageChange callback is triggered on every click, including when disabled or on the current page - but requirement #5 explicitly states it should only fire when the page actually changes. The click handlers on <li> elements bypass the disabled state entirely, causing unnecessary callbacks. Additionally, the pagination info display logic is incorrect - it caps the upper bound at 42 on all pages, but should only cap on the final page (e.g., with perPage=20 on page 2, it currently shows '21-42 of 42' but should show '21-40 of 42'). You need to move the onClick handlers to the <a> elements and add conditional guards like if (newPage !== currentPage && newPage >= 1 && newPage <= pageCount) onPageChange(newPage). Also remove the accidental sdsds.md file and replace hardcoded 42 values with the total prop for dynamic behavior.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
|
|
||
| <p className="lead" data-cy="info"> | ||
| Page 1 (items 1 - 5 of 42) | ||
| Page {currentPage} (items {firstItem + 1} -{' '} | ||
| {lastItems > 42 ? 42 : lastItems} of 42) |
There was a problem hiding this comment.
The onClick handler on <li> always calls onPageChange, even when disabled. According to requirement #5, the callback should only be triggered if the page was actually changed. Currently, clicking the disabled prev button still calls onPageChange(currentPage - 1) which evaluates to onPageChange(0) when on page 1. Move the page change logic to the <a> onClick handler or add guards to prevent calling onPageChange when disabled.
|
|
||
| {/* Move this markup to Pagination */} | ||
| <ul className="pagination"> | ||
| <li className="page-item disabled"> | ||
| <a | ||
| data-cy="prevLink" | ||
| className="page-link" | ||
| href="#prev" | ||
| aria-disabled="true"> | ||
| « | ||
| </a> | ||
| </li> | ||
| <li className="page-item active"> | ||
| <a data-cy="pageLink" className="page-link" href="#1"> | ||
| 1 | ||
| </a> | ||
| </li> | ||
| <li className="page-item"> | ||
| <a data-cy="pageLink" className="page-link" href="#2"> | ||
| 2 | ||
| </a> | ||
| </li> | ||
| <li className="page-item"> | ||
| <a data-cy="pageLink" className="page-link" href="#3"> | ||
| 3 | ||
| </a> | ||
| </li> | ||
| <li className="page-item"> | ||
| <a data-cy="pageLink" className="page-link" href="#4"> | ||
| 4 | ||
| </a> | ||
| </li> | ||
| <li className="page-item"> | ||
| <a data-cy="pageLink" className="page-link" href="#5"> | ||
| 5 | ||
| </a> | ||
| </li> | ||
| <li className="page-item"> | ||
| <a data-cy="pageLink" className="page-link" href="#6"> | ||
| 6 | ||
| </a> | ||
| </li> | ||
| <li className="page-item"> | ||
| <a data-cy="pageLink" className="page-link" href="#7"> | ||
| 7 | ||
| </a> | ||
| </li> | ||
| <li className="page-item"> | ||
| <a data-cy="pageLink" className="page-link" href="#8"> | ||
| 8 | ||
| </a> | ||
| </li> | ||
| <li className="page-item"> | ||
| <a data-cy="pageLink" className="page-link" href="#9"> | ||
| 9 | ||
| </a> | ||
| </li> | ||
| <li className="page-item"> | ||
| <a | ||
| data-cy="nextLink" | ||
| className="page-link" | ||
| href="#next" | ||
| aria-disabled="false"> | ||
| » | ||
| </a> | ||
| </li> | ||
| </ul> | ||
| <Pagination | ||
| total={items.length} | ||
| perPage={perPage} | ||
| currentPage={currentPage} |
There was a problem hiding this comment.
Same issue as prev button - onPageChange is called on every click, including when disabled. Clicking the disabled next button on the last page still triggers the callback with the same page number.
| <p className="lead" data-cy="info"> | ||
| Page 1 (items 1 - 5 of 42) | ||
| Page {currentPage} (items {firstItem + 1} -{' '} |
There was a problem hiding this comment.
Hardcoded 42 should be replaced with total prop to properly display the actual total count when it changes.
| <p className="lead" data-cy="info"> | ||
| Page 1 (items 1 - 5 of 42) | ||
| Page {currentPage} (items {firstItem + 1} -{' '} | ||
| {lastItems > 42 ? 42 : lastItems} of 42) |
There was a problem hiding this comment.
Hardcoded 42 should use total prop for consistency with the actual data length.
|
|
||
| const newItems = items.slice(firstItem, lastItems); | ||
|
|
||
| return ( |
There was a problem hiding this comment.
Redundant .map(n => n) - this creates a new array with the same values. Use getNumbers(1, pageCount) directly, or use .map with a meaningful transformation if needed.
| <li | ||
| className={cn('page-item', { disabled: currentPage === 1 })} | ||
| onClick={() => onPageChange(currentPage <= 1 ? 1 : currentPage - 1)} | ||
| > | ||
| <a | ||
| data-cy="prevLink" | ||
| className="page-link" | ||
| href="#prev" | ||
| aria-disabled={currentPage === 1} | ||
| > | ||
| « | ||
| </a> |
There was a problem hiding this comment.
The onClick handler is on the <li> element instead of <a>. This means clicking on disabled items still triggers the callback. Move onClick to the <a> element and add a condition to prevent calling onPageChange when already on page 1.
| className={cn('page-item', { disabled: currentPage === 1 })} | ||
| onClick={() => onPageChange(currentPage <= 1 ? 1 : currentPage - 1)} |
There was a problem hiding this comment.
The onClick handler on <li> always calls onPageChange even when on the first page. Requirement #5 states callback should be triggered only if page was changed. When currentPage === 1, clicking previous should not call onPageChange at all.
| <li | ||
| className={cn('page-item', { disabled: currentPage === pageCount })} | ||
| onClick={() => | ||
| onPageChange(currentPage >= pageCount ? pageCount : currentPage + 1) | ||
| } |
There was a problem hiding this comment.
The onClick handler is on the <li> element instead of <a>. This means clicking on disabled items still triggers the callback. Move onClick to the <a> element and add a condition to prevent calling onPageChange when already on the last page.
| onClick={() => | ||
| onPageChange(currentPage >= pageCount ? pageCount : currentPage + 1) |
There was a problem hiding this comment.
The onClick handler always calls onPageChange even when already on the last page. Requirement #5 states callback should be triggered only if page was changed. When currentPage === pageCount, clicking next should not call onPageChange at all.
| className={cn('page-item', { disabled: currentPage === 1 })} | ||
| onClick={() => onPageChange(currentPage <= 1 ? 1 : currentPage - 1)} |
There was a problem hiding this comment.
The pagination info display logic is incorrect. Using lastItems > 42 ? 42 : lastItems caps the upper bound on ALL pages, but it should only cap on the LAST page. For example, with perPage=20 on page 2: current code shows 'items 21 - 42 of 42' but should show 'items 21 - 40 of 42'.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
The numbered page links in Pagination.tsx directly call onPageChange(count) instead of using the handlePageChange guard function, violating requirement #5 that onPageChange should only trigger when the page actually changes. This must be fixed by updating line 47 to use handlePageChange(count) for consistency.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
| className="page-link" | ||
| onClick={() => onPageChange(count)} |
There was a problem hiding this comment.
This calls onPageChange directly without checking if the page actually changed. For consistency with the prev/next buttons (which use handlePageChange), this should also use handlePageChange(count) to ensure the callback is only triggered when the page actually changes (requirement #5).
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Your solution is approved. All nine requirements have been successfully implemented, including proper pagination logic, data-cy attributes for testing, page change guards, navigation controls with disabled states, and the per-page selector. The fix to use handlePageChange(count) instead of directly calling onPageChange on numbered page links was done correctly - this ensures the callback only triggers when the page actually changes. Great job on the clean TypeScript implementation and proper component structure!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
DEMO LINK