Skip to content

add task solution#1514

Open
annaskobara wants to merge 1 commit into
mate-academy:masterfrom
annaskobara:develop
Open

add task solution#1514
annaskobara wants to merge 1 commit into
mate-academy:masterfrom
annaskobara:develop

Conversation

@annaskobara

Copy link
Copy Markdown

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review Summary

I am approving your solution because all core pagination requirements are implemented correctly and there are no critical blockers that would prevent the task from functioning as intended. Your Pagination component is stateless with the correct props and default currentPage, onPageChange only fires when the page actually changes, and the prev/next controls, active page highlighting, and disabled states are all handled correctly. The per-page selector has the required options (3, 5, 10, 20), resets to page 1 on change, and the info text (Page X (items A - B of N)) is computed accurately.

The only notable mismatch is around the optional React Router requirement: you manage page and perPage via window.location.search and history.pushState in App.tsx and Pagination.tsx instead of using Router hooks like useSearchParams/useNavigate. Functionally this still satisfies the behavior of syncing URL query params, but it does not literally use React Router as described in the starred requirement; if your project already includes React Router, refactoring to useSearchParams for reading/writing ?page and perPage would make it fully aligned. As it stands, this is not a functional blocker, just an opportunity to better match the intended approach. Overall, your implementation is solid and meets the essential criteria; nice work on keeping the Pagination component clean and controlled via props.


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Footnotes

  1. Rate AI review example

Comment thread src/App.tsx
Comment on lines +21 to +28
useEffect(() => {
const params = new URLSearchParams(window.location.search);
params.set('page', currentPage.toString());
params.set('perPage', perPage.toString());

const newUrl = `${window.location.pathname}?${params.toString()}`;
window.history.pushState({}, '', newUrl);
}, [currentPage, perPage]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You update the URL query params manually with window.history.pushState. The optional requirement (#15/#18) mentions using React Router to persist page and perPage; if your project is already using React Router, consider using its hooks (e.g. useSearchParams) instead of direct window access to better match that requirement.

Comment thread src/App.tsx
Comment on lines +10 to +13
const params = new URLSearchParams(window.location.search);
const page = parseInt(params.get('page') || '1', 10);
return isNaN(page) || page < 1 ? 1 : page;
});

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Defaulting currentPage to 1 in the props destructuring fulfills the requirement that this prop be optional with a default of 1, and it keeps the component stateless as requested.

Comment thread src/App.tsx
Comment on lines +23 to +32
params.set('page', currentPage.toString());
params.set('perPage', perPage.toString());

const newUrl = `${window.location.pathname}?${params.toString()}`;
window.history.pushState({}, '', newUrl);
}, [currentPage, perPage]);

const totalItems = items.length;
const startItemIndex = (currentPage - 1) * perPage;
const endItemIndex = Math.min(startItemIndex + perPage, totalItems);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Your handlePageClick correctly prevents default anchor navigation and only calls onPageChange when the new page is different and within 1..totalPages, which satisfies the requirement that onPageChange only fire when the page actually changes.

Comment thread src/App.tsx
Comment on lines +64 to 69
value={perPage}
onChange={handlePerPageChange}
>
<option value="3">3</option>
<option value="5">5</option>
<option value="10">10</option>

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 aria-disabled attributes and disabled classes on prev/next links meet the requirement to disable navigation when on the first or last page; make sure not to change these attributes or tests may fail.

Comment on lines +9 to +10

export const Pagination: React.FC<Props> = ({

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 task’s optional requirement (*) explicitly mentions using React Router to save and read ?page and perPage from the URL; here you are manually reading from window.location.search instead of using router APIs like useSearchParams, which does not satisfy that specific requirement.

Comment on lines +21 to +27
const isLastPage = currentPage === totalPages;

const handlePageClick = (
event: React.MouseEvent<HTMLAnchorElement>,
page: number,
) => {
event.preventDefault();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Similarly, URL updates are handled with window.history.pushState rather than React Router navigation (e.g., useNavigate or setSearchParams), so query param synchronization is not implemented via React Router as requested in the description.

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