-
Notifications
You must be signed in to change notification settings - Fork 0
feat: pagination of books #19
Merged
+131
−21
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
a538c67
feat: add more search params to open library API
martakam 2c9d89a
feat: add basic pagination to BookGrid
martakam 0b59b8c
feat: show correct number of pages
martakam 80fd2ed
refactor: move page state to parent component
martakam 8deab27
fix: show "Loading books..." when changing pages
martakam a2e0939
Merge branch 'main' into feat/pagination
martakam 399cbc7
style: use kebab-case for CSS classnames for Pagination component
martakam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| .pagination { | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: center; | ||
| gap: 1rem; | ||
| padding: 0.75rem 0; | ||
| } | ||
|
|
||
| .paginationButton { | ||
| display: flex; | ||
| align-items: center; | ||
| justify-content: center; | ||
| width: 6rem; | ||
| padding: 0.5rem 1.25rem; | ||
| color: var(--theme-color); | ||
| background-color: white; | ||
| border: 1px solid var(--border-color); | ||
| border-radius: 0.5rem; | ||
| cursor: pointer; | ||
| transition: 0.15s ease-in-out; | ||
| } | ||
|
|
||
| .paginationButton:hover:not(:disabled) { | ||
| background-color: #f3f4f6; | ||
| border-color: #9ca3af; | ||
| } | ||
|
|
||
| .paginationButton:disabled { | ||
| color: var(--muted); | ||
| background-color: var(--muted-background); | ||
| border-color: var(--border-color); | ||
| cursor: not-allowed; | ||
| } | ||
|
|
||
| .paginationInfo { | ||
| font-weight: 500; | ||
| width: 5rem; | ||
| text-align: center; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import styles from "./Pagination.module.css"; | ||
|
|
||
| function Pagination({ | ||
| totalPages, | ||
| currentPage, | ||
| onPageChange, | ||
| }: { | ||
| totalPages: number; | ||
| currentPage: number; | ||
| onPageChange: (page: number) => void; | ||
| }) { | ||
| const handlePageChange = (newPage: number) => { | ||
| window.scrollTo({ top: 0, behavior: "smooth" }); | ||
| onPageChange(newPage); | ||
| }; | ||
|
|
||
| return ( | ||
| <section className={styles.pagination}> | ||
| <button | ||
| className={styles.paginationButton} | ||
| onClick={() => handlePageChange(currentPage - 1)} | ||
| disabled={currentPage === 1} | ||
| > | ||
| Previous | ||
| </button> | ||
| <span className={styles.paginationInfo}> | ||
| {currentPage} of {totalPages} | ||
| </span> | ||
| <button | ||
| className={styles.paginationButton} | ||
| onClick={() => handlePageChange(currentPage + 1)} | ||
| disabled={currentPage === totalPages} | ||
| > | ||
| Next | ||
| </button> | ||
| </section> | ||
| ); | ||
| } | ||
|
|
||
| export { Pagination }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.