-
Notifications
You must be signed in to change notification settings - Fork 79
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 #646
The head ref may contain hidden characters: "Next.js-\uACE0\uC7AC\uC131-sprint9"
[고재성] Sprint9 #646
Changes from 1 commit
93a0e93
b2e37bd
6f8bbb0
e11e25f
212e864
4dc5dd0
1a64a17
b591ab4
75672d0
88c122b
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Article } from "@/@types/api"; | ||
import Image from "next/image"; | ||
import Medal from "@/public/ic_medal.png"; | ||
import Heart from "@/public/heart.png"; | ||
import { formatDate } from "@/utils/dateformat"; | ||
|
||
export default function ArticleCard({ article }: { article: Article }) { | ||
const formattedDate = formatDate(new Date(article.createdAt)); | ||
return ( | ||
<div className="w-[400px] bg-coolGray-50 px-10 rounded-[8px]"> | ||
<div className="w-[120px] h-[30px] bg-primaryColor flex justify-center items-center rounded-b-[32px] p-2 gap-1"> | ||
<Image src={Medal} width={20} height={20} alt="medal" /> | ||
<p className="text-white">Best</p> | ||
</div> | ||
<div className="h-[100px] flex justify-between my-4 relative"> | ||
<p className="w-[240px] font-semibold text-lg mb-5">{article.title}</p> | ||
<div className="w-[80px] relative"> | ||
{article.image ? ( | ||
<Image | ||
src={article.image} | ||
alt="thumbnail" | ||
fill | ||
className="object-fit" | ||
/> | ||
) : null} | ||
</div> | ||
</div> | ||
<div className="flex justify-between text-sm text-coolGray-600"> | ||
<div className="flex gap-2 pb-5"> | ||
<p>{article.writer.nickname}</p> | ||
<div className="flex gap-1"> | ||
<Image | ||
src={Heart} | ||
width={14} | ||
height={14} | ||
alt="heart" | ||
className="h-[16px]" | ||
/> | ||
<p>{article.likeCount}</p> | ||
</div> | ||
</div> | ||
<p>{formattedDate}</p> | ||
</div> | ||
</div> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { Article, ArticleListResponse } from "@/@types/api"; | ||
import ArticleCard from "@/components/boards/ArticleCard"; | ||
|
||
export default function BestArticle({ articles }: { articles: Article[] }) { | ||
return ( | ||
<div> | ||
<h1 className="text-xl font-bold mb-5">베스트 게시글</h1> | ||
<div className="flex gap-5"> | ||
{articles.slice(0, 3).map((article) => ( | ||
<ArticleCard key={article.id} article={article} /> | ||
))} | ||
</div> | ||
</div> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = { | ||
reactStrictMode: true, | ||
} | ||
images: { | ||
domains: ["sprint-fe-project.s3.ap-northeast-2.amazonaws.com"], | ||
}, | ||
}; | ||
|
||
module.exports = nextConfig | ||
module.exports = nextConfig; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import axios from "axios"; | ||
import { Article } from "@/@types/api"; | ||
import BestArticle from "@/components/boards/BestArticle"; | ||
|
||
export async function getStaticProps() { | ||
try { | ||
const API_URL = "https://panda-market-api.vercel.app/articles"; | ||
const query = { | ||
orderBy: "like", | ||
}; | ||
|
||
const res = await axios.get(API_URL, { params: query }); | ||
const articles: Article[] = res.data.list; | ||
|
||
return { | ||
props: { | ||
articles, | ||
}, | ||
}; | ||
} catch (error) { | ||
console.error("API 요청 중 에러 발생:", error); | ||
return { | ||
props: { | ||
articles: [], | ||
}, | ||
}; | ||
} | ||
} | ||
|
||
export default function Board({ articles }: { articles: Article[] }) { | ||
return ( | ||
<div> | ||
<div className="w-[1200px] mx-auto mt-5"> | ||
<BestArticle articles={articles} /> | ||
</div> | ||
</div> | ||
); | ||
} |
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. 파일명을 date로 바꾸는게 확장성에서 좋을 것 같아요~ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export function formatDate(date: Date): string { | ||
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. format한 date를 얻는 것이기 때문에 |
||
return date | ||
.toLocaleDateString("ko-KR", { | ||
year: "numeric", | ||
month: "2-digit", | ||
day: "2-digit", | ||
}) | ||
.replace(/(\.\s*)$/, ""); // 마지막 마침표 제거 | ||
} |
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.
components/Header/index.tsx 로 하면 import 할 때 중복으로 Header/Header 이렇게 안써도 되는 것 참고해주세요~