Skip to content

Commit

Permalink
feat:BLOG-67 페이지 넘기는 컴포넌트 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
ryu9663 committed Jun 16, 2024
1 parent 9301a79 commit ea91088
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 14 deletions.
4 changes: 4 additions & 0 deletions src/app/_components/Pagination/index.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.pagination_wrapper {
display: flex;
gap: 10px;
}
43 changes: 43 additions & 0 deletions src/app/_components/Pagination/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"use client";

import Link from "next/link";
import { usePathname, useSearchParams } from "next/navigation";
import styles from "./index.module.scss";

export const Pagination = () => {
const searchParams = useSearchParams();
const pathname = usePathname();
const currentPage = Number(searchParams.get("currentPage"));
const pageSize = Number(searchParams.get("pageSize"));

return (
<ul className={styles.pagination_wrapper}>
<li>
<Link
href={{
pathname: `${pathname}`,
query: {
currentPage: currentPage - 1,
pageSize,
},
}}
>
이전 페이지
</Link>
</li>
<li>
<Link
href={{
pathname: `${pathname}`,
query: {
currentPage: currentPage + 1,
pageSize,
},
}}
>
다음 페이지
</Link>
</li>
</ul>
);
};
14 changes: 12 additions & 2 deletions src/app/_components/Posts/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import React, { PropsWithChildren } from "react";
import styles from "./index.module.scss";
export const Posts = ({ children }: PropsWithChildren) => (
<section className={styles["post_wrapper"]}>{children}</section>
import Cards from "@/app/_components/Cards";
import { Pagination } from "@/app/_components/Pagination";
import { PostType } from "@/types";

interface PostsProps {
posts: PostType[];
}
export const Posts = ({ posts }: PostsProps) => (
<section className={styles["post_wrapper"]}>
<Cards articles={posts} />
<Pagination />
</section>
);
5 changes: 1 addition & 4 deletions src/app/posts/[category]/[subCategory]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Cards from "@/app/_components/Cards";
import { Posts } from "@/app/_components/Posts";
import { getPosts } from "@/app/api/dato/getPosts";
import { PostType, SearchParamsType } from "@/types";
Expand Down Expand Up @@ -67,9 +66,7 @@ export default async function PostsPageFilteredBySubCategory({
<>
<h2 className={styles.heading}>{`${subCategory}`}</h2>

<Posts>
<Cards articles={posts} />
</Posts>
<Posts posts={posts} />
</>
);
}
Expand Down
5 changes: 1 addition & 4 deletions src/app/posts/[category]/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Cards from "@/app/_components/Cards";
import { Posts } from "@/app/_components/Posts";
import { getPosts } from "@/app/api/dato/getPosts";
import { PostType, SearchParamsType } from "@/types";
Expand Down Expand Up @@ -58,9 +57,7 @@ export default async function PostsPageFilteredByCategory({
<>
<h2 className={styles.heading}>{`${category}`}</h2>

<Posts>
<Cards articles={posts} />
</Posts>
<Posts posts={posts} />
</>
);
}
Expand Down
5 changes: 1 addition & 4 deletions src/app/posts/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Cards from "@/app/_components/Cards";
import { getPosts } from "@/app/api/dato/getPosts";
import { Metadata } from "next";
import { PostType, SearchParamsType } from "@/types";
Expand Down Expand Up @@ -27,9 +26,7 @@ export default async function Home({ searchParams }: SearchParamsType) {
return (
<>
<h2 className={styles.heading}>{`게시글 전체 보기`}</h2>
<Posts>
<Cards articles={posts} />
</Posts>
<Posts posts={posts} />
</>
);
}

0 comments on commit ea91088

Please sign in to comment.