-
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
[신승헌] sprint10 #632
The head ref may contain hidden characters: "Next.js-\uC2E0\uC2B9\uD5CC-sprint10"
[신승헌] sprint10 #632
Changes from 1 commit
14ab44a
c68a248
a9c3fe8
287eaaa
d35d413
fedc2ae
e65364d
096204e
8ce5d26
cdd40ad
e9e552d
1230632
ba764dd
0a764eb
5137cb2
9941c08
f818ee2
7826d77
e1211cc
369410b
1bfe187
24601a3
1e00784
9ebe7c8
c3e8b44
12a4711
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,23 +1,35 @@ | ||
import ProfileDefault from "@/public/images/profile_default.png"; | ||
import EmptyComments from "@/public/images/Img_reply_empty.png"; | ||
import { Comment } from "@/types"; | ||
import formatDate from "@/utils/formatDate"; | ||
import Image from "next/image"; | ||
|
||
export default function CommentList() { | ||
export default function CommentList({ comments }: { comments: Comment[] }) { | ||
return ( | ||
<div className="flex flex-col gap-6 mb-6"> | ||
<div>Content</div> | ||
<div className="flex items-center gap-2"> | ||
<Image | ||
src={ProfileDefault} | ||
width={32} | ||
height={32} | ||
alt="댓글프로필이미지" | ||
/> | ||
<div> | ||
<p className="text-gray-600">nickname</p> | ||
<p className="text-gray-400">times ago</p> | ||
</div> | ||
</div> | ||
<hr className="h-[1px] bg-gray-200" /> | ||
</div> | ||
<> | ||
{comments && | ||
comments.map((comment) => { | ||
return ( | ||
<div className="flex flex-col gap-6 mb-6" key={comment.id}> | ||
<div>{comment.content}</div> | ||
<div className="flex items-center gap-2"> | ||
<Image | ||
src={ProfileDefault} | ||
width={32} | ||
height={32} | ||
alt="댓글프로필이미지" | ||
/> | ||
<div> | ||
<p className="text-gray-600">{comment.writer.nickname}</p> | ||
<p className="text-gray-400"> | ||
{formatDate(comment.updatedAt)} | ||
</p> | ||
</div> | ||
</div> | ||
<hr className="h-[1px] bg-gray-200" /> | ||
</div> | ||
); | ||
})} | ||
</> | ||
); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,23 +7,38 @@ import Image from "next/image"; | |
import Link from "next/link"; | ||
import instance from "@/lib/axios"; | ||
import { GetServerSidePropsContext } from "next"; | ||
import { Article } from "@/types"; | ||
import { Article, Comment } from "@/types"; | ||
import formatDate from "@/utils/formatDate"; | ||
import CommentList from "@/components/Boards/CommentList"; | ||
|
||
const COMMENTS_MAX = 5; | ||
|
||
export async function getServerSideProps(context: GetServerSidePropsContext) { | ||
const id = context.query.id; | ||
|
||
const res = await instance.get(`/articles/${id}`); | ||
const article = res.data ?? []; | ||
const articlesRes = await instance.get(`/articles/${id}`); | ||
const commentsRes = await instance.get( | ||
`/articles/${id}/comments?limit=${COMMENTS_MAX}` | ||
); | ||
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. 위와같이 async함수에 여러개의 await구문이 들어간다면 해당 함수는 await구문마다 해당 비동기 함수가 끝날때까지 기다리게 됩니다. |
||
|
||
const article: Article = articlesRes.data ?? {}; | ||
const comments: Comment[] = commentsRes.data.list ?? []; | ||
|
||
return { | ||
props: { | ||
article, | ||
comments, | ||
}, | ||
}; | ||
} | ||
|
||
export default function Article({ article }: { article: Article }) { | ||
export default function Article({ | ||
article, | ||
comments, | ||
}: { | ||
article: Article; | ||
comments: Comment[]; | ||
}) { | ||
return ( | ||
<div className="flex flex-col gap-8"> | ||
<div className="flex flex-col gap-4"> | ||
|
@@ -83,7 +98,7 @@ export default function Article({ article }: { article: Article }) { | |
name="comment" | ||
/> | ||
</div> | ||
<CommentList /> | ||
<CommentList comments={comments} /> | ||
<Link | ||
className="w-60 h-12 bg-blue-default rounded-full flex justify-center items-center gap-2 mx-auto" | ||
href="/boards" | ||
|
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.