Skip to content

add task solution#1485

Open
Ivadriil wants to merge 4 commits into
mate-academy:masterfrom
Ivadriil:develop
Open

add task solution#1485
Ivadriil wants to merge 4 commits into
mate-academy:masterfrom
Ivadriil:develop

Conversation

@Ivadriil
Copy link
Copy Markdown

Copy link
Copy Markdown

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment thread src/App.tsx Outdated
Comment on lines +21 to +24

<p className="lead" data-cy="info">
Page 1 (items 1 - 5 of 42)
Page {currentPage} (items {firstItem + 1} -{' '}
{lastItems > 42 ? 42 : lastItems} of 42)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/App.tsx
Comment on lines 50 to +54

{/* 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}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/App.tsx
Comment on lines 22 to +23
<p className="lead" data-cy="info">
Page 1 (items 1 - 5 of 42)
Page {currentPage} (items {firstItem + 1} -{' '}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoded 42 should be replaced with total prop to properly display the actual total count when it changes.

Comment thread src/App.tsx Outdated
<p className="lead" data-cy="info">
Page 1 (items 1 - 5 of 42)
Page {currentPage} (items {firstItem + 1} -{' '}
{lastItems > 42 ? 42 : lastItems} of 42)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hardcoded 42 should use total prop for consistency with the actual data length.

Comment thread src/App.tsx

const newItems = items.slice(firstItem, lastItems);

return (
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +22 to +33
<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>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +23 to +24
className={cn('page-item', { disabled: currentPage === 1 })}
onClick={() => onPageChange(currentPage <= 1 ? 1 : currentPage - 1)}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +50 to +54
<li
className={cn('page-item', { disabled: currentPage === pageCount })}
onClick={() =>
onPageChange(currentPage >= pageCount ? pageCount : currentPage + 1)
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +52 to +53
onClick={() =>
onPageChange(currentPage >= pageCount ? pageCount : currentPage + 1)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +23 to +24
className={cn('page-item', { disabled: currentPage === 1 })}
onClick={() => onPageChange(currentPage <= 1 ? 1 : currentPage - 1)}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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'.

Copy link
Copy Markdown

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment on lines +46 to +47
className="page-link"
onClick={() => onPageChange(count)}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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! ✨

Footnotes

  1. Rate AI review example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants