Skip to content
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

[김광호] sprint9 #260

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added assets/images/home/blankimg.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions assets/images/home/ic_search.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions assets/images/logo/img_badge.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions components/AllItemsSction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ interface AllItemsResponse {
}

function AllItem({ item }: { item: AllItemProps }) {

return (
<div className={style.AllItem}>
<Link href={`/items/${item.id}`}>
Expand All @@ -56,14 +55,15 @@ function AllItem({ item }: { item: AllItemProps }) {
);
}

const option = {"recent" : "최신순", "favorite" : "좋아요순"};

function AllItemsSection() {
const [alltItemsList, setAllItemsList] = useState<AllItemProps[]>([]);
const [itemCount, setItemCount] = useState<number>(getWidth());
const [order, setOrder] = useState<string>("recent");
const [poninter, setPoninter] = useState<number>(1);
const [title, setTitle] = useState<string>("전체 상품");
const [pageSize, setPageSize] = useState<number>(0);
const option = {"recent" : "최신순", "favorite" : "좋아요순"};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

좋네요!
상수는 컴포넌트 외부에서 선언해주시는게 깔끔하거든요

const AllItemsLoad = async (ItemCount: number, Order: string) => {
const response: AllItemsResponse = await CallItemSearch(poninter, ItemCount, Order);
setAllItemsList(response.list);
Expand Down
2 changes: 1 addition & 1 deletion components/BestItemsSection.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useEffect, useState } from "react";
import favicon from "@/assets/images/logo/favoriteIcon.svg";
import { CallItemSearch } from "@/pages/api/CallAPI";
import style from "@/assets/BestItemsSection.module.css";
import style from "@/styles/BestItemsSection.module.css";
import Link from "next/link";
import Image from "next/image";

Expand Down
77 changes: 54 additions & 23 deletions components/Bestarticles.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,67 @@
import style from "@/styles/BestArticles.module.scss";
import Image from "next/image";
import BestImage from "@/assets/images/logo/img_badge.svg";
import BlackImg from "@/assets/images/home/blankimg.jpg";
import favoriteIcon from "@/assets/images/logo/favoriteIcon.svg";
import DateFomet from "@/utils/DateFormet";

interface ArticlesProps {
id: number;
title: string;
content: string;
image: string | null;
likeCount: number;
createdAt: string;
updatedAt: string;
writer: {
id: number;
title: string;
content: string;
image: File | null;
likeCount: number;
createAt: Date;
updateAt: Date;
writer: {
id: number;
nickname: string;
};
}

nickname: string;
};
}

function BestArticles(articlesList: ArticlesProps[]) {
Comment on lines 8 to -18
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

타입 정의하는걸 조금 개선하면 어떨까요?

props로 전달받는걸 item 으로 받고싶다면 Props의 interface에 item 을 넣어주는게 좀더 좋을것같아요!
이름이 정확한 의미를 담고있는게 좋거든요...ㅠ

ArticlesProps 에 각 타입에 대한 정보를 넣는게 아니라 분리시켜주는거죠!

type Article = {
  ...
}

interface ArticlesProps {
  item: Article;
}

요런식으로 의미를 중첩해서 사용하는것보단 분리하는거에요 ㅎㅎ

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아 맞습니다 그방법도 있네요!

function Article({ item }: {item : ArticlesProps} ) {
return (
<div className={style.bestarticleslayer}>
<p>베스트 게시글</p>
<div></div>
<div>
<div>
<p>게시글</p>
<button>글쓰기</button>
<div className={style.articleData}>
<div className={style.articleDescription}>
<p className={style.articleTitle}>{item.title}</p>
{item.image ? (
<div className={style.articleImg}>
<Image src={item.image} alt="게시글 사진" fill />
</div>
) : (
<div>
<input></input>
<Image
src={BlackImg}
alt="빈 이미지"
className={style.blankImage}
/>
</div>
Comment on lines +27 to 38
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이미지를 못가져왔을때의 처리인데, Image 에 onError 를 통해서 처리할 수 있어요!

https://nextjs.org/docs/pages/api-reference/components/image 여기에 props 보시면 될것같구,
간단한 예시는...
https://velog.io/@yung315/nextimage-Error-handling
이거 참고해보시면 좋을것같아요!

</div>
)}
</div>
<div className={style.articleInfo}>
<div>

<p>{item.writer.nickname}</p>
<Image src={favoriteIcon} alt="하트아이콘" width={16} height={16} />
<p>{item.likeCount}</p>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

사소한거긴 한데, 숫자를 화면에 표시할떄 .toLocaleString() 을 해주는 습관을 들이시면 좋아요...!
완성도를 올리기 위해서.ㅎㅎ

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네! 알겠습니다.

</div>
<p>{DateFomet(item.updatedAt)}</p>
</div>
</div>
);
}


function BestArticles({ datalist }: { datalist: ArticlesProps[] }) {
return (
<div className={style.bestArticleLayer}>
<p className={style.bestArtitlceTitle}>베스트 게시글</p>
<div className={style.bestArticleList}>
{datalist.map((item) => (
<div className={style.bestArticle}>
<Image className={style.bestIcon} src={BestImage} alt="베스트 아이콘" width={102} height={30} />
<Article item={item} key={item.id} />
</div>
))}
</div>
</div>
);
Expand Down
10 changes: 0 additions & 10 deletions components/Recentarticles.tsx

This file was deleted.

62 changes: 62 additions & 0 deletions components/Recentarticles/Recentarticles.module.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
.recentArticlesLayer {
margin: 0 auto;
background-color: white;
.dataLayer {
background-color: #FCFCFC;
margin-bottom: 24px;
.articleData {
.articleDescription {
display: flex;
gap: 8px;
justify-content: space-between;
margin-bottom: 18px;
.articleTitle {
font-size: 20px;
font-weight: 600;
line-height: 32px;
color: #1f2937;
margin-right: 8px;
}
.articleImg {
width: 72px;
height: 72px;
border-radius: 6px;
background-color: white;
border: solid 1px var(--cool-Gray200);
position: relative;
}
.blankImage {
width: 72px;
height: 72px;
background-color: black;
}
}
.articleInfo {
display: flex;
justify-content: space-between;

.userIcon {
margin-right: 8px;
}

p {
font-size: 14px;
font-weight: 400;
line-height: 24px;
color: #4b5563;
}
div {
display: flex;
align-items: center;
p {
margin-right: 8px;
}
img {
margin-right: 4px;
}
}
}
}

}
}
68 changes: 68 additions & 0 deletions components/Recentarticles/Recentarticles.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import style from "./Recentarticles.module.scss"
import favoriteIcon from "@/assets/images/logo/favoriteIcon.svg";
import BlackImg from "@/assets/images/home/blankimg.jpg";
import DateFomet from "@/utils/DateFormet";
import Image from "next/image";
import MaskIcon from "@/assets/images/home/maskicon.png"

interface ArticlesProps {
id: number;
title: string;
content: string;
image: string | null;
likeCount: number;
createdAt: string;
updatedAt: string;
writer: {
id: number;
nickname: string;
};
}

function Article({ item }: {item : ArticlesProps }) {
Comment on lines +8 to +22
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기도 마찬가지일것같구요...

아까 타입을 잘 나눠두었으면 type ArticleType 을 export 해서 재활용 할 수 있을것같아요!ㅎㅎ

return (
<div className={style.articleData}>
<div className={style.articleDescription}>
<p className={style.articleTitle}>{item.title}</p>
{item.image ? (
<div className={style.articleImg}>
<Image src={item.image} alt="게시글 사진" fill />
</div>
) : (
<div>
<Image
src={BlackImg}
alt="빈 이미지"
className={style.blankImage}
/>
</div>
)}
</div>
<div className={style.articleInfo}>
<div>
<Image className={style.userIcon} src={MaskIcon} alt="유저아이콘" width={24} height={24}/>
<p>{item.writer.nickname}</p>
<p>{DateFomet(item.updatedAt)}</p>
</div>
<div>
<Image src={favoriteIcon} alt="하트아이콘" width={16} height={16} />
<p>{item.likeCount}</p>
</div>
</div>
</div>
);
}

function Recentarticles({ datalist } : {datalist: ArticlesProps[]}) {
return (
<div className={style.recentArticlesLayer}>
{datalist.map((item) => (
<div className={style.dataLayer}>
<Article item={item} key={item.id} />
</div>
))}
</div>
)
}

export default Recentarticles;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

endline 을 추가해주면 좋을것같아요...!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

맞습니다 아직 습관화가 덜 됬네요ㅠㅠㅠㅠ

28 changes: 28 additions & 0 deletions hook/useDevice.tsx
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

굳굳...! 잘 만드셨네욬ㅋㅋ 이런거 잘 만들어두면 유용하게 쓸 수 있어서 좋아요!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

멘토님이 전에 해주신걸 활용했습니다ㅎㅎ

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { useEffect, useState } from "react";
import { DeviceType, getDevice } from "@/utils/widthUtil";

const useDevice = () => {
const [mode, setMode] = useState<DeviceType>("desktop");

useEffect(() => {
const ReCount = () => {
const device = getDevice();
setMode(device);
};

window.addEventListener("resize", ReCount);

// 초기화
ReCount();

return () => {
window.removeEventListener("resize", ReCount);
};
}, []);

return {
mode,
};
};

export default useDevice;
Loading
Loading