From df4bc927e513acfbc8ebf763c3a512b250ae2a5a Mon Sep 17 00:00:00 2001
From: Minchan <98478661+itscold96@users.noreply.github.com>
Date: Wed, 14 Aug 2024 17:13:17 +0900
Subject: [PATCH 01/13] =?UTF-8?q?refactor(mentor):=20QueryClient=EB=A5=BC?=
=?UTF-8?q?=20Laytout=20=EC=BB=B4=ED=8F=AC=EB=84=8C=ED=8A=B8=EB=A1=9C=20?=
=?UTF-8?q?=EC=9D=B4=EB=8F=99?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
components/@shared/Layout.tsx | 5 +++-
components/boards/ArticleManagement.tsx | 1 +
pages/boards.tsx | 33 +++++++++++--------------
3 files changed, 19 insertions(+), 20 deletions(-)
diff --git a/components/@shared/Layout.tsx b/components/@shared/Layout.tsx
index 4cddf0659..47097f243 100644
--- a/components/@shared/Layout.tsx
+++ b/components/@shared/Layout.tsx
@@ -4,10 +4,13 @@ import styles from './Layout.module.scss';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
function Layout({ children }: { children: React.ReactNode }) {
+ const queryClient = new QueryClient();
return (
<>
- {children}
+
+ {children}
+
>
);
}
diff --git a/components/boards/ArticleManagement.tsx b/components/boards/ArticleManagement.tsx
index fb41e3ec5..dee23f9e8 100644
--- a/components/boards/ArticleManagement.tsx
+++ b/components/boards/ArticleManagement.tsx
@@ -28,6 +28,7 @@ function ArticleManagement({
}: ArticleManagementProps) {
const { innerWidth } = useWindowSize();
+ //TODO: 드롭다운 모듈화
return (
<>
diff --git a/pages/boards.tsx b/pages/boards.tsx
index 8e5a5edcc..1c5481c96 100644
--- a/pages/boards.tsx
+++ b/pages/boards.tsx
@@ -1,7 +1,6 @@
import styles from './boards.module.scss';
import { Suspense } from 'react';
import dynamic from 'next/dynamic';
-import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import getArticles, { IArticle } from '@/apis/getArticles';
import Link from 'next/link';
import Button from '@/components/@shared/Button';
@@ -24,28 +23,24 @@ export async function getServerSideProps() {
}
export default function Boards({ list }: { list: IArticle[] }) {
- const queryClient = new QueryClient();
-
// TODO: BestArticle, Article을 Link로 감싸서 prefetch 시켜야함
return (
-
-
-
베스트 게시글
- ...loading}>
-
-
-
-
-
-
게시글
-
-
-
-
-
+
+
베스트 게시글
+ ...loading}>
+
+
+
+
);
}
From 97f6bf7a3c4884a7708b1d14b24a736ac11c97bb Mon Sep 17 00:00:00 2001
From: Minchan <98478661+itscold96@users.noreply.github.com>
Date: Wed, 14 Aug 2024 17:52:37 +0900
Subject: [PATCH 02/13] =?UTF-8?q?refactor(borads):=20=EB=82=B4=EB=B6=80=20?=
=?UTF-8?q?=EC=BB=B4=ED=8F=AC=EB=84=8C=ED=8A=B8=20=EB=AA=A8=EB=93=88?=
=?UTF-8?q?=ED=99=94?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
components/boards/ArticleManagement.tsx | 4 +--
components/boards/ArticleSection.module.scss | 11 +++++++
components/boards/ArticleSection.tsx | 25 +++++++++------
components/boards/BestArticleList.tsx | 32 ++++++-------------
.../boards/BestArticleSection.module.scss | 14 ++++++++
components/boards/BestArticleSection.tsx | 20 ++++++++++++
pages/boards.module.scss | 15 ---------
pages/boards.tsx | 26 ++-------------
8 files changed, 76 insertions(+), 71 deletions(-)
create mode 100644 components/boards/BestArticleSection.module.scss
create mode 100644 components/boards/BestArticleSection.tsx
diff --git a/components/boards/ArticleManagement.tsx b/components/boards/ArticleManagement.tsx
index dee23f9e8..b88ae21d8 100644
--- a/components/boards/ArticleManagement.tsx
+++ b/components/boards/ArticleManagement.tsx
@@ -13,7 +13,7 @@ const orderByObject = {
interface ArticleManagementProps {
onSearchSubmit: (event: React.FormEvent) => void;
- onIsOpenClick: () => void;
+ onDropdownClick: () => void;
onOrderByClick: (event: React.MouseEvent) => void;
isDropdownOpen: boolean;
orderBy: orderType;
@@ -21,7 +21,7 @@ interface ArticleManagementProps {
function ArticleManagement({
onSearchSubmit,
- onIsOpenClick,
+ onDropdownClick: onIsOpenClick,
onOrderByClick,
isDropdownOpen,
orderBy,
diff --git a/components/boards/ArticleSection.module.scss b/components/boards/ArticleSection.module.scss
index 84741e0e4..a56a4e7e6 100644
--- a/components/boards/ArticleSection.module.scss
+++ b/components/boards/ArticleSection.module.scss
@@ -3,3 +3,14 @@
flex-direction: column;
gap: 24px;
}
+
+.titleAndButton {
+ display: flex;
+ justify-content: space-between;
+ margin-bottom: 24px;
+
+ & button {
+ width: 88px;
+ height: 42px;
+ }
+}
diff --git a/components/boards/ArticleSection.tsx b/components/boards/ArticleSection.tsx
index 562357e54..b2c0b326b 100644
--- a/components/boards/ArticleSection.tsx
+++ b/components/boards/ArticleSection.tsx
@@ -4,6 +4,8 @@ import { useState } from 'react';
import useToggle from '@/hooks/useToggle';
import styles from './ArticleSection.module.scss';
import dynamic from 'next/dynamic';
+import Link from 'next/link';
+import Button from '../@shared/Button';
const ArticleManagement = dynamic(() => import('./ArticleManagement'), {
ssr: false,
@@ -23,13 +25,11 @@ function ArticleSection({ initialArticleList }: ArticleSectionProps) {
) => {
const { value } = (event.target as HTMLDivElement).dataset;
- if (value) {
- // dataset에 있는 데이터로 재정렬 요청 후 토글 닫기
- const { list } = await getArticles({ order: value as orderType });
- setArticleList(() => list);
- setOrderBy(value as orderType);
- toggleIsOpen();
- }
+ // dataset에 있는 쿼리로 재정렬 요청 후 드롭다운 닫기
+ const { list } = await getArticles({ order: value as orderType });
+ setArticleList(() => list);
+ setOrderBy(value as orderType);
+ toggleIsOpen();
};
const handleSearchSubmit = async (
@@ -37,19 +37,26 @@ function ArticleSection({ initialArticleList }: ArticleSectionProps) {
) => {
event.preventDefault();
const { value } = (event.target as HTMLFormElement)['search'];
+ // 작성된 키워드로 검색 요청
const { list } = await getArticles({ keyword: value });
setArticleList(() => list);
};
- const handleIsOpenClick = () => {
+ const handleDropdownClick = () => {
toggleIsOpen();
};
return (
+
+
게시글
+
+
+
+
- {BestArticleList.map((bestArticle) => {
- const {
- id,
- title,
- writer: { nickname },
- image,
- likeCount,
- createdAt,
- } = bestArticle;
-
- const createDate = createdAt.split('T')[0];
- return (
-
- );
- })}
+ {BestArticleList.map((bestArticle) => (
+
+ ))}
>
);
diff --git a/components/boards/BestArticleSection.module.scss b/components/boards/BestArticleSection.module.scss
new file mode 100644
index 000000000..4ed4441fa
--- /dev/null
+++ b/components/boards/BestArticleSection.module.scss
@@ -0,0 +1,14 @@
+.bestArticleSection {
+ min-height: 257px;
+}
+
+.titleAndButton {
+ display: flex;
+ justify-content: space-between;
+ margin-bottom: 24px;
+
+ & button {
+ width: 88px;
+ height: 42px;
+ }
+}
diff --git a/components/boards/BestArticleSection.tsx b/components/boards/BestArticleSection.tsx
new file mode 100644
index 000000000..ec61a65eb
--- /dev/null
+++ b/components/boards/BestArticleSection.tsx
@@ -0,0 +1,20 @@
+import { Suspense } from 'react';
+import styles from './BestArticleSection.module.scss';
+import dynamic from 'next/dynamic';
+
+const BestArticleList = dynamic(() => import('../boards/BestArticleList'), {
+ ssr: false,
+});
+
+function BestArticleSection() {
+ return (
+
+
베스트 게시글
+ ...loading}>
+
+
+
+ );
+}
+
+export default BestArticleSection;
diff --git a/pages/boards.module.scss b/pages/boards.module.scss
index 4a61b21c3..a65e1e87d 100644
--- a/pages/boards.module.scss
+++ b/pages/boards.module.scss
@@ -9,19 +9,4 @@
line-height: 23.87px;
margin-bottom: 24px;
}
-
- .bestArticleSection {
- min-height: 257px;
- }
-
- .titleAndButton {
- display: flex;
- justify-content: space-between;
- margin-bottom: 24px;
-
- & button {
- width: 88px;
- height: 42px;
- }
- }
}
diff --git a/pages/boards.tsx b/pages/boards.tsx
index 1c5481c96..3c6ac0951 100644
--- a/pages/boards.tsx
+++ b/pages/boards.tsx
@@ -2,14 +2,8 @@ import styles from './boards.module.scss';
import { Suspense } from 'react';
import dynamic from 'next/dynamic';
import getArticles, { IArticle } from '@/apis/getArticles';
-import Link from 'next/link';
-import Button from '@/components/@shared/Button';
import ArticleSection from '@/components/boards/ArticleSection';
-
-const BestArticleList = dynamic(
- () => import('../components/boards/BestArticleList'),
- { ssr: false }
-);
+import BestArticleSection from '@/components/boards/BestArticleSection';
export async function getServerSideProps() {
// 최신순이 기본값
@@ -23,24 +17,10 @@ export async function getServerSideProps() {
}
export default function Boards({ list }: { list: IArticle[] }) {
- // TODO: BestArticle, Article을 Link로 감싸서 prefetch 시켜야함
return (
-
-
베스트 게시글
- ...loading}>
-
-
-
-
+
+
);
}
From 402c7da9ac881c1548d1e9c5931006744a784736 Mon Sep 17 00:00:00 2001
From: Minchan <98478661+itscold96@users.noreply.github.com>
Date: Wed, 14 Aug 2024 18:06:28 +0900
Subject: [PATCH 03/13] =?UTF-8?q?remove:=EB=A6=AC=EC=95=A1=ED=8A=B8?=
=?UTF-8?q?=EC=97=90=EC=84=9C=20=EC=82=AC=EC=9A=A9=ED=96=88=EB=8D=98=20Cus?=
=?UTF-8?q?tomImage=20=EA=B3=B5=EC=9A=A9=20=EC=BB=B4=ED=8F=AC=EB=84=8C?=
=?UTF-8?q?=ED=8A=B8=20=EC=A0=9C=EA=B1=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
components/@shared/CustomImage.tsx | 46 ------------------
components/@shared/HeaderLinkSection.tsx | 4 +-
components/boards/Article.module.scss | 58 +++++++++++++----------
components/boards/Article.tsx | 20 ++------
components/boards/ArticleManagement.tsx | 4 +-
components/boards/BestArticle.module.scss | 5 ++
components/boards/BestArticle.tsx | 15 ++----
7 files changed, 50 insertions(+), 102 deletions(-)
delete mode 100644 components/@shared/CustomImage.tsx
diff --git a/components/@shared/CustomImage.tsx b/components/@shared/CustomImage.tsx
deleted file mode 100644
index d947f4fe8..000000000
--- a/components/@shared/CustomImage.tsx
+++ /dev/null
@@ -1,46 +0,0 @@
-import classNames from 'classnames';
-import Image, { StaticImageData } from 'next/image';
-
-interface ImageProps {
- src: string | StaticImageData;
- alt: string;
- width: number;
- height: number;
- radius?: number;
- aspectRatio?: number;
- className?: string;
- priority?: boolean;
- onClick?: () => void;
-}
-
-function CustomImage({
- src,
- alt,
- width,
- height,
- radius,
- className,
- onClick,
- aspectRatio,
- priority,
-}: ImageProps) {
- const imageStyle = {
- borderRadius: `${radius}px` || '',
- aspectRatio: `${aspectRatio}` || '',
- };
-
- return (
-
- );
-}
-
-export default CustomImage;
diff --git a/components/@shared/HeaderLinkSection.tsx b/components/@shared/HeaderLinkSection.tsx
index dde39d4c9..fd9fdaf09 100644
--- a/components/@shared/HeaderLinkSection.tsx
+++ b/components/@shared/HeaderLinkSection.tsx
@@ -1,7 +1,6 @@
import logoImg from '@/public/images/home/logoAndTypo.png';
import typoImg from '@/public/images/home/typo.png';
import Link from 'next/link';
-import CustomImage from './CustomImage';
import { useRouter } from 'next/router';
import useWindowSize from '@/hooks/useWindowSize';
import {
@@ -13,6 +12,7 @@ import {
import classNames from 'classnames';
import styles from './HeaderLinkSection.module.scss';
import { DEVICE_MAX_WIDTH } from '@/constants/mediaQuerySize';
+import Image from 'next/image';
function HeaderLinkSection() {
const { innerWidth } = useWindowSize();
@@ -23,7 +23,7 @@ function HeaderLinkSection() {
return (
-
-
{nickname}
{createdAt}
-
+
{likeCount}
diff --git a/components/boards/ArticleManagement.tsx b/components/boards/ArticleManagement.tsx
index b88ae21d8..2ac499f87 100644
--- a/components/boards/ArticleManagement.tsx
+++ b/components/boards/ArticleManagement.tsx
@@ -1,10 +1,10 @@
import styles from './ArticleManagement.module.scss';
-import CustomImage from '../@shared/CustomImage';
import { DEVICE_MAX_WIDTH } from '@/constants/mediaQuerySize';
import sortIcon from '@/public/images/market/sort-icon.png';
import dropDownIcon from '@/public/images/market/order-dropdown.png';
import { orderType } from '@/apis/getArticles';
import useWindowSize from '@/hooks/useWindowSize';
+import Image from 'next/image';
const orderByObject = {
recent: '최신순',
@@ -44,7 +44,7 @@ function ArticleManagement({
{innerWidth > DEVICE_MAX_WIDTH.mobile && (
{orderByObject[orderBy]}
)}
- DEVICE_MAX_WIDTH.mobile ? dropDownIcon : sortIcon
}
diff --git a/components/boards/BestArticle.module.scss b/components/boards/BestArticle.module.scss
index ac23719ff..67cbbfced 100644
--- a/components/boards/BestArticle.module.scss
+++ b/components/boards/BestArticle.module.scss
@@ -37,6 +37,11 @@
line-height: 32px;
color: var(--cool-gray-800);
+ img {
+ border-radius: 8px;
+ border: 1px solid var(--cool-gray-200);
+ }
+
@media #{$underTabletSize} {
margin-bottom: 40px;
}
diff --git a/components/boards/BestArticle.tsx b/components/boards/BestArticle.tsx
index a245a9b0a..0f9afaf17 100644
--- a/components/boards/BestArticle.tsx
+++ b/components/boards/BestArticle.tsx
@@ -1,7 +1,7 @@
import styles from './BestArticle.module.scss';
-import CustomImage from '../@shared/CustomImage';
import BestIcon from '@/public/images/boards/best-icon.png';
import likeImg from '@/public/images/market/like-icon.png';
+import Image from 'next/image';
interface BestArticleProps {
title: string;
@@ -21,7 +21,7 @@ function BestArticle({
return (
@@ -46,12 +44,7 @@ function BestArticle({
{nickname}
-
+
{likeCount}
From 51d9fbbaed612c3225790da2af4d48d948b9f5c6 Mon Sep 17 00:00:00 2001
From: Minchan <98478661+itscold96@users.noreply.github.com>
Date: Wed, 14 Aug 2024 19:46:41 +0900
Subject: [PATCH 04/13] =?UTF-8?q?design(ArticleSection):=20=EB=B6=88?=
=?UTF-8?q?=ED=95=84=EC=9A=94=ED=95=9C=20=EB=A7=88=EC=A7=84=20=EC=A0=9C?=
=?UTF-8?q?=EA=B1=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
components/boards/ArticleSection.module.scss | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/components/boards/ArticleSection.module.scss b/components/boards/ArticleSection.module.scss
index a56a4e7e6..62f117abd 100644
--- a/components/boards/ArticleSection.module.scss
+++ b/components/boards/ArticleSection.module.scss
@@ -6,8 +6,8 @@
.titleAndButton {
display: flex;
+ align-items: center;
justify-content: space-between;
- margin-bottom: 24px;
& button {
width: 88px;
From 19e3e99c174c81beb90584e5e9da1fe510c87f01 Mon Sep 17 00:00:00 2001
From: Minchan <98478661+itscold96@users.noreply.github.com>
Date: Wed, 14 Aug 2024 19:59:06 +0900
Subject: [PATCH 05/13] =?UTF-8?q?refactor:=20getArticles=20=ED=95=A8?=
=?UTF-8?q?=EC=88=98=20=EB=82=B4=EB=B6=80=EC=97=90=20URLSearchParams=20api?=
=?UTF-8?q?=20=EC=A0=81=EC=9A=A9?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
apis/getArticles.ts | 17 ++++++++++++-----
components/boards/BestArticleList.tsx | 6 +++---
hooks/queries/useArticlesQuery.ts | 4 ++--
3 files changed, 17 insertions(+), 10 deletions(-)
diff --git a/apis/getArticles.ts b/apis/getArticles.ts
index f95f5f993..143c75c89 100644
--- a/apis/getArticles.ts
+++ b/apis/getArticles.ts
@@ -23,20 +23,27 @@ interface ArticlesResponse {
}
export interface GetArticlesProps {
- page?: string;
+ page?: number;
+ size?: number;
order?: orderType;
keyword?: string;
- size?: string;
}
const getArticles = async ({
- page = '1',
+ page = 1,
order = 'recent',
- size = '10',
+ size = 10,
keyword = '',
}: GetArticlesProps): Promise => {
+ const params = new URLSearchParams({
+ page: page.toString(),
+ pageSize: size.toString(),
+ orderBy: order,
+ keyword,
+ });
+ console.log('params: ', params.toString());
const { data } = await axiosInstance.get(
- `/${ARTICLES_QUERY_KEY}?page=${page}&pageSize=${size}&orderBy=${order}&keyword=${keyword}`
+ `/${ARTICLES_QUERY_KEY}?${params.toString()}`
);
return data;
diff --git a/components/boards/BestArticleList.tsx b/components/boards/BestArticleList.tsx
index ec5385e5c..12cb21c8e 100644
--- a/components/boards/BestArticleList.tsx
+++ b/components/boards/BestArticleList.tsx
@@ -9,10 +9,10 @@ function BestArticleList() {
const { innerWidth } = useWindowSize();
const querySize =
innerWidth > DEVICE_MAX_WIDTH.tablet // 태블릿 사이즈보다 크면 3개
- ? '3'
+ ? 3
: innerWidth > DEVICE_MAX_WIDTH.mobile // 태블릿 사이즈보다 작고 모바일 사이즈보다 크면 2개
- ? '2'
- : '1'; //그보다 작으면 1개
+ ? 2
+ : 1; //그보다 작으면 1개
const {
data: { list: BestArticleList },
diff --git a/hooks/queries/useArticlesQuery.ts b/hooks/queries/useArticlesQuery.ts
index 8f1e23366..7adf94691 100644
--- a/hooks/queries/useArticlesQuery.ts
+++ b/hooks/queries/useArticlesQuery.ts
@@ -2,10 +2,10 @@ import getArticles, { GetArticlesProps } from '@/apis/getArticles';
import { ARTICLES_QUERY_KEY } from '@/constants/queryKeys';
import { useSuspenseQuery } from '@tanstack/react-query';
-const INITIAL_PAGE_SIZE = '10';
+const INITIAL_PAGE_SIZE = 10;
const useArticlesQuery = ({
- page = '1',
+ page = 1,
order = 'recent',
size = INITIAL_PAGE_SIZE,
keyword = '',
From 2e1f4f265ffff61c4548a3d7a27be1e3c5848f0d Mon Sep 17 00:00:00 2001
From: Minchan <98478661+itscold96@users.noreply.github.com>
Date: Wed, 14 Aug 2024 20:11:27 +0900
Subject: [PATCH 06/13] =?UTF-8?q?refactor(mentor):=20=EB=B0=98=EC=9D=91?=
=?UTF-8?q?=ED=98=95=20=EC=BF=BC=EB=A6=AC=20mixin=EC=9C=BC=EB=A1=9C=20?=
=?UTF-8?q?=EC=88=98=EC=A0=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
components/@shared/Button.tsx | 2 +-
components/@shared/Header.module.scss | 6 ++---
.../@shared/HeaderLinkSection.module.scss | 13 +++++-----
components/@shared/Layout.module.scss | 3 ++-
.../boards/ArticleManagement.module.scss | 5 ++--
components/boards/BestArticle.module.scss | 4 ++--
components/boards/BestArticleList.module.scss | 2 +-
styles/_variables.scss | 24 +++++++++++++++++++
8 files changed, 43 insertions(+), 16 deletions(-)
diff --git a/components/@shared/Button.tsx b/components/@shared/Button.tsx
index 1ff1f5962..08aa4428b 100644
--- a/components/@shared/Button.tsx
+++ b/components/@shared/Button.tsx
@@ -22,7 +22,7 @@ function Button({
return (