-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #148 from jihwooon/issue-76
Pagination 기능 구현 및 Books 페이지 개선
- Loading branch information
Showing
4 changed files
with
75 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
name: server | ||
name: book-store Server | ||
|
||
on: | ||
push: | ||
|
This file contains 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 |
---|---|---|
@@ -1,13 +1,64 @@ | ||
import { useSearchParams } from "react-router-dom"; | ||
import { styled } from "styled-components"; | ||
import { Pagination as IPagination } from "../../models/pagination.model"; | ||
import Button from "../common/Button"; | ||
import { LIMIT } from "../constants/pagination"; | ||
import { QUERYSTRING } from "../constants/querystring"; | ||
|
||
interface Props { | ||
pagination: IPagination | ||
} | ||
|
||
const Pagination = ({ pagination }: Props) => { | ||
const [searchparams, setSearchParams] = useSearchParams() | ||
const { totalCount, currentPage } = pagination || {}; | ||
const pages: number = Math.ceil(totalCount / LIMIT) | ||
|
||
const handleClickPage = (page: number) => { | ||
const newSearchParams = new URLSearchParams(searchparams); | ||
|
||
newSearchParams.set(QUERYSTRING.PAGE, page.toString()) | ||
|
||
setSearchParams(newSearchParams); | ||
} | ||
|
||
const Pagination = () => { | ||
return ( | ||
<div> | ||
<h1>Pagination</h1> | ||
</div> | ||
<PaginationStyle> | ||
{ | ||
pages > 0 && ( | ||
<ol> | ||
{Array(pages) | ||
.fill(0) | ||
.map((_, index) => ( | ||
<li key={index}> | ||
<Button | ||
size="small" | ||
scheme={currentPage ? "primary" : "normal"} | ||
onClick={() => handleClickPage(index + 1)} | ||
> | ||
{index + 1} | ||
</Button> | ||
</li> | ||
))} | ||
</ol> | ||
) | ||
} | ||
</PaginationStyle> | ||
); | ||
}; | ||
|
||
const Paginationstyled = styled.div``; | ||
const PaginationStyle = styled.div` | ||
display: flex; | ||
justify-content: start; | ||
align-items: center; | ||
padding: 24px 0; | ||
ol { | ||
list-style: none; | ||
display: flex; | ||
gap: 8px; | ||
margin: 0; | ||
} | ||
`; | ||
|
||
export default Pagination; |
This file contains 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 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