Skip to content

Commit d63c126

Browse files
committed
Fix: CI 에러 제거
1 parent 9f10236 commit d63c126

File tree

7 files changed

+132
-6
lines changed

7 files changed

+132
-6
lines changed

components/Pagination.tsx

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
import Image from "next/image";
2+
import Link from "next/link";
3+
import { useRouter } from "next/router";
4+
import { useEffect, useState } from "react";
5+
6+
interface PaginationProps {
7+
totalCount: number;
8+
}
9+
10+
const Pagination: React.FC<PaginationProps> = ({ totalCount }) => {
11+
const router = useRouter();
12+
const LiStyle = "relative w-12 h-12 rounded-lg bg-gray900";
13+
const buttonStyle = "flex justify-center items-center h-full text-black400";
14+
const { page, pageSize } = router.query;
15+
16+
const currentPage = Number(page);
17+
const currentPageSize = Number(pageSize);
18+
const totalPages = Math.ceil(totalCount / currentPageSize);
19+
const [maxPagesToShow, setMaxPagesToShow] = useState(2);
20+
21+
// 화면 크기 변화에 따라 pageSize와 maxPagesToShow를 설정
22+
useEffect(() => {
23+
const handleResize = () => {
24+
const width = window.innerWidth;
25+
setMaxPagesToShow(width > 1024 ? 5 : 3);
26+
};
27+
28+
// 초기 설정 및 리사이즈 이벤트 리스너 추가
29+
handleResize();
30+
window.addEventListener("resize", handleResize);
31+
32+
return () => {
33+
window.removeEventListener("resize", handleResize);
34+
};
35+
}, []);
36+
37+
// 페이지 리스트 생성 함수
38+
const getPageNumbers = () => {
39+
const pages = [];
40+
41+
if (totalPages <= maxPagesToShow) {
42+
// 전체 페이지 수가 표시 가능한 페이지 수 이하인 경우 모든 페이지 표시
43+
for (let i = 1; i <= totalPages; i++) pages.push(i);
44+
} else {
45+
// 첫 페이지와 마지막 페이지는 항상 표시
46+
pages.push(1);
47+
let start = Math.max(2, currentPage - 1);
48+
let end = Math.min(totalPages - 1, currentPage + 1);
49+
50+
if (currentPage > 3) pages.push("...");
51+
for (let i = start; i <= end; i++) pages.push(i);
52+
if (currentPage < totalPages - 2) pages.push("...");
53+
pages.push(totalPages);
54+
}
55+
56+
return pages;
57+
};
58+
59+
return (
60+
<ul className="flex justify-center gap-[10px] my-10">
61+
<li className={LiStyle}>
62+
<Link
63+
href={`/link?page=${currentPage - 1}&pageSize=${currentPageSize}`}
64+
className={`${buttonStyle} ${currentPage > 1 ? "text-black500" : "pointer-events-none"}`}
65+
>
66+
<Image
67+
src={
68+
currentPage > 1
69+
? "/icons/pagination-left-active.png"
70+
: "/icons/pagination-left.png"
71+
}
72+
height={24}
73+
width={24}
74+
alt="prev"
75+
/>
76+
</Link>
77+
</li>
78+
79+
{/* 페이지 번호와 생략 표시 */}
80+
{getPageNumbers().map((pageNum, index) =>
81+
typeof pageNum === "number" ? (
82+
<li key={index} className={LiStyle}>
83+
<Link
84+
href={`/link?page=${pageNum}&pageSize=${pageSize}`}
85+
className={`${buttonStyle} ${pageNum === currentPage ? "text-black500" : "text-black400"}`}
86+
>
87+
{pageNum}
88+
</Link>
89+
</li>
90+
) : (
91+
<li
92+
key={index}
93+
className={`${LiStyle} flex items-center justify-center text-black400`}
94+
>
95+
...
96+
</li>
97+
)
98+
)}
99+
100+
<li className={LiStyle}>
101+
<Link
102+
href={`/link?page=${currentPage + 1}&pageSize=${pageSize}`}
103+
className={`${buttonStyle} ${currentPage < totalPages ? "text-black500" : "pointer-events-none"}`}
104+
>
105+
<Image
106+
src={
107+
currentPage < totalPages
108+
? "/icons/pagination-right-active.png"
109+
: "/icons/pagination-right.png"
110+
}
111+
width={24}
112+
height={24}
113+
alt="next"
114+
/>
115+
</Link>
116+
</li>
117+
</ul>
118+
);
119+
};
120+
121+
export default Pagination;

hooks/useRerenderFolderList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { useEffect, useRef } from "react";
22
import { getFolders } from "@/lib/api/folder";
33
import { FolderData } from "@/types/folderTypes";
44

5-
// Folder 관련 드랍다운이 닫혔을 때 화면에 update된 FolderList를 보여주는 커스텀 훅
5+
// 모달이 닫혔을 때 새로운 FolderList를 보여주는 커스텀 훅
66
const useRerenderFolderList = (
77
isOpen: boolean,
88
setFolderList: React.Dispatch<React.SetStateAction<FolderData[]>>

pages/api/links/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
1212
// 유저의 전체 링크 조회
1313
try {
1414
const response = await axiosInstance.get(`/links`, {
15-
params: { page, pageSize, search },
15+
params: { page, pageSize, search }, // 만약 아무런 값이 없으면 알아서 예외시킴
1616
headers: { Authorization: `Bearer ${accessToken}` },
1717
});
1818
return res.status(201).json(response.data);

pages/favorite/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { GetServerSideProps, GetServerSidePropsContext } from "next";
22
import { proxy } from "@/lib/api/axiosInstanceApi";
3-
import LinkCard from "@/components/LinkCard";
43
import CardsLayout from "@/components/Layout/CardsLayout";
54
import Container from "@/components/Layout/Container";
5+
import LinkCard from "@/components/Link/LinkCard";
66

77
interface FavoriteDataType {
88
id: number;

pages/link/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ const LinkPage = ({
5656
const { linkCardList, setLinkCardList } = useLinkCardStore();
5757
const [folderList, setFolderList] = useState(initialFolderList);
5858

59+
// 링크페이지의 query가 바뀌면 새로운 리스트로 업데이트 해주는 훅
5960
useFetchLinks(router.query, setLinkCardList);
6061

6162
// 클라이언트에서 초기 목록을 설정

store/useLinkCardStore.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
11
import { deleteLinkURL, getLinks, putLinkURL } from "@/lib/api/link";
22
import { create } from "zustand";
3+
import { LinkData } from "@/types/linkTypes";
34

45
interface UpdateLinkBody {
56
url: string;
67
}
78

89
interface LinkCardStore {
9-
linkCardList: LinkCardDataType[];
10-
setLinkCardList: (list: LinkCardDataType[]) => void;
10+
linkCardList: LinkData[];
11+
setLinkCardList: (list: LinkData[]) => void;
1112
updateLink: (linkId: number, body: UpdateLinkBody) => Promise<void>;
1213
deleteLink: (linkId: number) => Promise<void>;
1314
}
1415

1516
export const useLinkCardStore = create<LinkCardStore>((set) => ({
1617
linkCardList: [],
1718

18-
setLinkCardList: (list: LinkCardDataType[]) => {
19+
setLinkCardList: (list: LinkData[]) => {
1920
set({ linkCardList: list });
2021
},
2122

tailwind.config.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ const config: Config = {
1414
black100: "#000",
1515
black200: "#111322",
1616
black300: "#373740",
17+
black400: "#c4c4c4",
18+
black500: "#1f1f1f",
1719
red100: "#ff5b56",
1820
gray100: "#f0f6ff",
1921
gray200: "#e7effb",
@@ -23,6 +25,7 @@ const config: Config = {
2325
gray600: "#6b6b6b",
2426
gray700: "#676767",
2527
gray800: "#CFCFCF",
28+
gray900: "#f7f7f7",
2629
purple100: "#6d6afe",
2730
},
2831
screens: {

0 commit comments

Comments
 (0)