-
Notifications
You must be signed in to change notification settings - Fork 39
[윤정환] sprint6 #193
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
The head ref may contain hidden characters: "React-\uC724\uC815\uD658-sprint6"
[윤정환] sprint6 #193
Changes from 8 commits
8c979cb
1fae8b3
3f4cba4
6c1a427
c837f68
74e2995
56be9bd
fc09a4b
7057166
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 |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import XIcon from "../assets/icons/ic_X.svg"; | ||
|
|
||
| const XButton = ({ onClick, value = null, className = "btn" }) => { | ||
| return ( | ||
| <button | ||
| style={{ height: "24px" }} | ||
| className={className} | ||
| value={value} | ||
| type="button" | ||
| onClick={onClick} | ||
| > | ||
| <img src={XIcon} alt="삭제 버튼" /> | ||
| </button> | ||
| ); | ||
| }; | ||
|
|
||
| export default XButton; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,6 +10,7 @@ | |
| margin: 0 auto; | ||
| border-bottom: 1px solid var(--color-border-grey); | ||
| gap: var(--space-sm); | ||
| z-index: 999; | ||
|
||
| } | ||
|
|
||
| .link-container { | ||
|
|
@@ -56,10 +57,7 @@ | |
| display: inline-block; | ||
| width: 128px; | ||
| height: 48px; | ||
| text-decoration: none; | ||
| color: var(--color-white); | ||
| padding: 12px 20px; | ||
| text-align: center; | ||
| border-radius: 8px; | ||
| font-weight: 500; | ||
| font-size: 16px; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ import { useCallback, useEffect, useState } from "react"; | |
| import ArrowButton from "./ArrowButton"; | ||
| import PageButton from "./PageButton"; | ||
| import styles from "./PaginationNav.module.css"; | ||
| import usePagination from "./hooks/UsePagination"; | ||
|
||
|
|
||
| const PaginationNav = ({ | ||
| signalSearch, | ||
|
|
@@ -10,8 +11,12 @@ const PaginationNav = ({ | |
| currentPage, | ||
| breakpoint, | ||
| }) => { | ||
| const [pageList, setPageList] = useState([[1]]); | ||
| const [pageListIndex, setPageListIndex] = useState(0); | ||
| const { pageList, pageListIndex, onMovePageList } = usePagination( | ||
| totalPage, | ||
| breakpoint, | ||
| signalSearch, | ||
| onClickPage | ||
| ); | ||
| const PrevArrowButton = { | ||
| shape: "<", | ||
| direction: -1, | ||
|
|
@@ -23,48 +28,6 @@ const PaginationNav = ({ | |
| endIndex: pageList.length - 1, | ||
| }; | ||
|
|
||
| const resetPagination = useCallback(() => { | ||
| setPageListIndex((prev) => 0); | ||
| onClickPage((prev) => 1); | ||
| }, [onClickPage]); | ||
|
|
||
| const onMovePageList = (direction) => { | ||
| setPageListIndex((prev) => prev + direction); | ||
| onClickPage((prev) => pageList[pageListIndex + direction][0]); | ||
| }; | ||
|
|
||
| const calcPageList = (totalPage) => { | ||
| if (!totalPage) { | ||
| setPageList((prev) => [[1]]); | ||
| return; | ||
| } | ||
| const wholePageList = []; | ||
| const dividedPageList = []; | ||
| let count = 0; | ||
|
|
||
| for (let i = 1; i <= totalPage; i++) { | ||
| if (count === 5) { | ||
| wholePageList.push([...dividedPageList]); | ||
| dividedPageList.splice(0); | ||
| count = 0; | ||
| } | ||
| dividedPageList.push(i); | ||
| count++; | ||
| if (totalPage === i) { | ||
| wholePageList.push([...dividedPageList]); | ||
| } | ||
| } | ||
| setPageList((prev) => [...wholePageList]); | ||
| }; | ||
|
|
||
| useEffect(() => { | ||
| calcPageList(totalPage); | ||
| }, [totalPage]); | ||
|
|
||
| useEffect(() => { | ||
| resetPagination(); | ||
| }, [signalSearch, breakpoint, resetPagination]); | ||
|
|
||
| return ( | ||
| <div className={styles.container}> | ||
| <ArrowButton | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import { useCallback, useEffect, useState } from "react"; | ||
|
|
||
| const BUTTONS_PER_PAGE = 5; | ||
|
|
||
| const usePagination = (totalPage, breakpoint, signalSearch, onClickPage) => { | ||
| const [pageList, setPageList] = useState([[1]]); | ||
| const [pageListIndex, setPageListIndex] = useState(0); | ||
|
|
||
| const resetPagination = useCallback(() => { | ||
| setPageListIndex((prev) => 0); | ||
| onClickPage((prev) => 1); | ||
| }, [onClickPage]); | ||
|
|
||
| const onMovePageList = (direction) => { | ||
| setPageListIndex((prev) => prev + direction); | ||
| onClickPage((prev) => pageList[pageListIndex + direction][0]); | ||
| }; | ||
|
|
||
| const calcPageList = useCallback((totalPage) => { | ||
| if (!totalPage) { | ||
| setPageList((prev) => [[1]]); | ||
| return; | ||
| } | ||
| const wholePageList = []; | ||
| const dividedPageList = []; | ||
| let count = 0; | ||
|
|
||
| for (let i = 1; i <= totalPage; i++) { | ||
| if (count === BUTTONS_PER_PAGE) { | ||
|
Collaborator
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.
|
||
| wholePageList.push([...dividedPageList]); | ||
| dividedPageList.splice(0); | ||
| count = 0; | ||
| } | ||
| dividedPageList.push(i); | ||
| count++; | ||
| if (totalPage === i) { | ||
| wholePageList.push([...dividedPageList]); | ||
| } | ||
| } | ||
| setPageList((prev) => [...wholePageList]); | ||
| }, []); | ||
|
|
||
| useEffect(() => { | ||
| calcPageList(totalPage); | ||
| }, [totalPage, calcPageList]); | ||
|
|
||
| useEffect(() => { | ||
| resetPagination(); | ||
| }, [signalSearch, breakpoint, resetPagination]); | ||
|
|
||
| return { pageList, pageListIndex, onMovePageList }; | ||
| }; | ||
|
|
||
| export default usePagination; | ||
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.
조건문이 너무 복잡해보이네요! 리턴문은 최대한 명확하고 간결하게 유지해봅시다.
이정도로 정리해보는건 어떨까요? :)