-
Notifications
You must be signed in to change notification settings - Fork 1.7k
done #1519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
done #1519
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,84 @@ | ||
| export const Pagination = () => {}; | ||
| import React from 'react'; | ||
|
|
||
| type Props = { | ||
| total: number; | ||
| perPage: number; | ||
| currentPage?: number; | ||
| onPageChange: (page: number) => void; | ||
| }; | ||
|
|
||
| const Pagination: React.FC<Props> = ({ | ||
| total, | ||
| perPage, | ||
| currentPage = 1, | ||
| onPageChange, | ||
| }) => { | ||
| const totalPages = Math.ceil(total / perPage); | ||
| const pages = Array.from({ length: totalPages }, (_, i) => i + 1); | ||
|
|
||
| return ( | ||
| <ul className="pagination"> | ||
| {/* PREV */} | ||
| <li className={`page-item ${currentPage === 1 ? 'disabled' : ''}`}> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's better to use |
||
| <a | ||
| data-cy="prevLink" | ||
| className="page-link" | ||
| href="#prev" | ||
| aria-disabled={currentPage === 1} | ||
| onClick={e => { | ||
| e.preventDefault(); | ||
| if (currentPage > 1) { | ||
| onPageChange(currentPage - 1); | ||
| } | ||
| }} | ||
| > | ||
| « | ||
| </a> | ||
| </li> | ||
|
|
||
| {/* PAGES */} | ||
| {pages.map(page => ( | ||
| <li | ||
| key={page} | ||
| className={`page-item ${currentPage === page ? 'active' : ''}`} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's better to use |
||
| > | ||
| <a | ||
| data-cy="pageLink" | ||
| className="page-link" | ||
| href={`#${page}`} | ||
| onClick={e => { | ||
| e.preventDefault(); | ||
| if (page !== currentPage) { | ||
| onPageChange(page); | ||
| } | ||
| }} | ||
| > | ||
| {page} | ||
| </a> | ||
| </li> | ||
| ))} | ||
|
|
||
| {/* NEXT */} | ||
| <li | ||
| className={`page-item ${currentPage === totalPages ? 'disabled' : ''}`} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's better to use |
||
| > | ||
| <a | ||
| data-cy="nextLink" | ||
| className="page-link" | ||
| href="#next" | ||
| aria-disabled={currentPage === totalPages} | ||
| onClick={e => { | ||
| e.preventDefault(); | ||
| if (currentPage < totalPages) { | ||
| onPageChange(currentPage + 1); | ||
| } | ||
| }} | ||
| > | ||
| » | ||
| </a> | ||
| </li> | ||
| </ul> | ||
| ); | ||
| }; | ||
|
|
||
| export default Pagination; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,9 @@ | ||
| import { createRoot } from 'react-dom/client'; | ||
| import ReactDOM from 'react-dom/client'; | ||
| import { BrowserRouter } from 'react-router-dom'; | ||
| import App from './App'; | ||
|
|
||
| import { App } from './App'; | ||
|
|
||
| createRoot(document.getElementById('root') as HTMLElement).render(<App />); | ||
| ReactDOM.createRoot(document.getElementById('root')!).render( | ||
| <BrowserRouter> | ||
| <App /> | ||
| </BrowserRouter>, | ||
| ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
currentPageis required inProps, but the requirements specify it must be optional and default to 1 if not provided (checklist items #2 and #20). Consider makingcurrentPageoptional in the type (e.g.currentPage?: number) and providing a default value of 1 in the component destructuring.