-
Notifications
You must be signed in to change notification settings - Fork 39
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
The head ref may contain hidden characters: "Next-\uAE40\uAD11\uD638-sprint9"
[김광호] sprint9 #260
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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
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. 타입 정의하는걸 조금 개선하면 어떨까요? props로 전달받는걸 item 으로 받고싶다면 Props의 interface에 item 을 넣어주는게 좀더 좋을것같아요! ArticlesProps 에 각 타입에 대한 정보를 넣는게 아니라 분리시켜주는거죠! type Article = {
...
}
interface ArticlesProps {
item: Article;
} 요런식으로 의미를 중첩해서 사용하는것보단 분리하는거에요 ㅎㅎ 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. 아 맞습니다 그방법도 있네요! |
||
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
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. 이미지를 못가져왔을때의 처리인데, Image 에 onError 를 통해서 처리할 수 있어요! https://nextjs.org/docs/pages/api-reference/components/image 여기에 props 보시면 될것같구, |
||
</div> | ||
)} | ||
</div> | ||
<div className={style.articleInfo}> | ||
<div> | ||
|
||
<p>{item.writer.nickname}</p> | ||
<Image src={favoriteIcon} alt="하트아이콘" width={16} height={16} /> | ||
<p>{item.likeCount}</p> | ||
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. 사소한거긴 한데, 숫자를 화면에 표시할떄 .toLocaleString() 을 해주는 습관을 들이시면 좋아요...! 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. 네! 알겠습니다. |
||
</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> | ||
); | ||
|
This file was deleted.
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; | ||
} | ||
} | ||
} | ||
} | ||
|
||
} | ||
} |
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
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. 여기도 마찬가지일것같구요... 아까 타입을 잘 나눠두었으면 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; | ||
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. endline 을 추가해주면 좋을것같아요...! 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. 맞습니다 아직 습관화가 덜 됬네요ㅠㅠㅠㅠ |
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. 굳굳...! 잘 만드셨네욬ㅋㅋ 이런거 잘 만들어두면 유용하게 쓸 수 있어서 좋아요! 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. 멘토님이 전에 해주신걸 활용했습니다ㅎㅎ |
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; |
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.
좋네요!
상수는 컴포넌트 외부에서 선언해주시는게 깔끔하거든요