-
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.
- Loading branch information
Showing
3 changed files
with
109 additions
and
54 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,38 +1,66 @@ | ||
//Pagination.jsx | ||
|
||
// Pagination.jsx | ||
import PropTypes from "prop-types"; | ||
import "./styles/Pagination.scss"; | ||
|
||
const Pagination = ({ currentPage, totalPages, onPageChange }) => { | ||
const pageNumbers = []; | ||
for (let i = 1; i <= totalPages; i++) { | ||
pageNumbers.push(i); | ||
} | ||
const getPageNumbers = () => { | ||
const pageNumbers = []; | ||
let startPage = Math.max(currentPage - 2, 0); | ||
let endPage = Math.min(startPage + 4, totalPages - 1); | ||
|
||
// 끝부분에 도달했을 때 시작 페이지 조정 | ||
if (endPage - startPage < 4) { | ||
startPage = Math.max(endPage - 4, 0); | ||
} | ||
|
||
for (let i = startPage; i <= endPage; i++) { | ||
pageNumbers.push(i); | ||
} | ||
|
||
return pageNumbers; | ||
}; | ||
|
||
const pageNumbers = getPageNumbers(); | ||
const showPrevButton = currentPage > 0; | ||
const showNextButton = currentPage < totalPages - 1; | ||
|
||
return ( | ||
<div className="pagination"> | ||
<button | ||
onClick={() => onPageChange(currentPage - 1)} | ||
disabled={currentPage === 1} | ||
> | ||
< | ||
</button> | ||
{pageNumbers.map((number) => ( | ||
{showPrevButton && ( | ||
<button | ||
key={number} | ||
onClick={() => onPageChange(number)} | ||
className={currentPage === number ? "active" : ""} | ||
onClick={() => onPageChange(currentPage - 1)} | ||
className="nav-button" | ||
> | ||
{number} | ||
< | ||
</button> | ||
)} | ||
|
||
{pageNumbers.map((pageNum) => ( | ||
<button | ||
key={pageNum} | ||
onClick={() => onPageChange(pageNum)} | ||
className={currentPage === pageNum ? "active" : ""} | ||
> | ||
{pageNum + 1} | ||
</button> | ||
))} | ||
<button | ||
onClick={() => onPageChange(currentPage + 1)} | ||
disabled={currentPage === totalPages} | ||
> | ||
> | ||
</button> | ||
|
||
{showNextButton && ( | ||
<button | ||
onClick={() => onPageChange(currentPage + 1)} | ||
className="nav-button" | ||
> | ||
> | ||
</button> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
Pagination.propTypes = { | ||
currentPage: PropTypes.number.isRequired, | ||
totalPages: PropTypes.number.isRequired, | ||
onPageChange: PropTypes.func.isRequired, | ||
}; | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,35 @@ | ||
//SortButton.jsx | ||
|
||
// SortButtons.jsx | ||
import PropTypes from "prop-types"; | ||
import "./styles/SortButtons.scss"; | ||
|
||
const SortButtons = ({ onSort }) => { | ||
const SortButtons = ({ onSort, currentSort }) => { | ||
return ( | ||
<div className="sort-buttons"> | ||
<button onClick={() => onSort("latest")}>최신순</button> | ||
<button onClick={() => onSort("oldest")}>오래된 순</button> | ||
<button onClick={() => onSort("popular")}>인기순</button> | ||
<button | ||
onClick={() => onSort("latest")} | ||
className={currentSort === "latest" ? "active" : ""} | ||
> | ||
최신순 | ||
</button> | ||
<button | ||
onClick={() => onSort("oldest")} | ||
className={currentSort === "oldest" ? "active" : ""} | ||
> | ||
오래된 순 | ||
</button> | ||
<button | ||
onClick={() => onSort("popular")} | ||
className={currentSort === "popular" ? "active" : ""} | ||
> | ||
인기순 | ||
</button> | ||
</div> | ||
); | ||
}; | ||
|
||
SortButtons.propTypes = { | ||
onSort: PropTypes.func.isRequired, | ||
currentSort: PropTypes.string.isRequired, | ||
}; | ||
|
||
export default SortButtons; |
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