-
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.
Browse files
Browse the repository at this point in the history
* feat: 클라이언트 서비스의 페이지네이션 컴포넌트 구현 #141 * feat: 학생의 마일스톤 획득내역, 실적 목록 페이지네이션 처리 * feat: 나의 마일스톤 획득 내역에 페이지네이션 처리 #150 * fix: 학생의 실적 목록 조회 api의 totalElements가 제대로 불러와지지 않는 문제 해결 #150 --------- Co-authored-by: amaran-th <[email protected]>
- Loading branch information
Showing
6 changed files
with
180 additions
and
85 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
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
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
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 |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* eslint-disable prettier/prettier */ | ||
/* eslint-disable import/no-extraneous-dependencies */ | ||
/* eslint-disable max-len */ | ||
import { VscChevronLeft } from '@react-icons/all-files/vsc/VscChevronLeft'; | ||
import { VscChevronRight } from '@react-icons/all-files/vsc/VscChevronRight'; | ||
import Link from 'next/link'; | ||
|
||
export interface PaginationProps { | ||
currentPage: number; | ||
pageSize: number; | ||
totalItems: number; | ||
pathname: string; | ||
query?: string; | ||
} | ||
|
||
const Pagination = ({ currentPage, pageSize, totalItems, pathname, query }: PaginationProps) => { | ||
const buttonPerPage = 10; | ||
|
||
const totalPageCount = Math.ceil(totalItems / pageSize); | ||
const totalPages = Array.from({ length: totalPageCount }, (v, i) => i + 1); | ||
|
||
const showIdx = Math.floor((currentPage - 1) / buttonPerPage); | ||
const showPage = totalPages.slice(showIdx * buttonPerPage, (showIdx + 1) * buttonPerPage); | ||
|
||
const queries = query ? JSON.parse(query) : null; | ||
|
||
const nextPageCalc = (showIdx + 1) * buttonPerPage + 1; | ||
const prevPage = showIdx === 0 ? 1 : showIdx * buttonPerPage; | ||
const nextPage = totalPageCount >= nextPageCalc ? nextPageCalc : totalPageCount; | ||
|
||
return ( | ||
<div className="flex w-full justify-center gap-4 [&>*]:rounded-sm [&>*]:border-[1px] [&>*]:border-admin-border"> | ||
<Link href={{ pathname, query: { ...queries, page: prevPage } }} className="h-8 w-8 p-1"> | ||
<VscChevronLeft className="h-full w-full text-base" /> | ||
</Link> | ||
{showPage.map((page) => ( | ||
<Link | ||
href={{ pathname, query: { ...queries, page } }} | ||
key={page} | ||
className={`flex h-8 w-8 items-center justify-center p-1 text-sm ${currentPage === page && 'bg-primary-main text-white'}`} | ||
> | ||
{page} | ||
</Link> | ||
))} | ||
<Link href={{ pathname, query: { ...queries, page: nextPage } }} className="h-8 w-8 p-1"> | ||
<VscChevronRight className="h-full w-full text-base" /> | ||
</Link> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Pagination; |