Skip to content

Commit 1f0fa33

Browse files
committed
article 페이지 완료(아마도..)
1 parent 73afc23 commit 1f0fa33

File tree

7 files changed

+62
-8
lines changed

7 files changed

+62
-8
lines changed

components/ArticleItem.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
import Image from "next/image";
22
import styles from "./ArticleItem.module.css";
33
import Hearts from "./Hearts";
4+
import { useRouter } from "next/router";
45

56
export default function ArticleItem({ article }) {
6-
console.log(article);
7+
const router = useRouter();
78
const updatedAt = article.updatedAt.split("T")[0];
9+
810
return (
9-
<div className={styles.article}>
11+
<div
12+
className={styles.article}
13+
onClick={() => {
14+
router.push(`/article/${article.id}`);
15+
}}
16+
>
1017
<div className={styles.content}>
1118
<div className={styles.title}>{article.title}</div>
1219
<Image src={"/default.png"} alt="이미지" width={48} height={48} />

components/ArticleItem.module.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
gap: 16px;
99

1010
border-bottom: var(--Cool-Gray-200, #e5e7eb) solid 1px;
11+
12+
cursor: pointer;
1113
}
1214

1315
.content {

components/BestArticleSection.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,22 @@ import axios from "axios";
44
import { useEffect, useState } from "react";
55
import styles from "./BestArticleSection.module.css";
66
import Hearts from "./Hearts";
7+
import { useRouter } from "next/router";
78

89
function BestArticle({ article }) {
10+
const router = useRouter();
11+
912
if (!article) {
1013
return <div>로딩 중...</div>;
1114
}
1215

1316
return (
14-
<div className={styles.item}>
17+
<div
18+
className={styles.item}
19+
onClick={() => {
20+
router.push(`/article/${article.id}`);
21+
}}
22+
>
1523
<div className={styles.bestMark}>
1624
<Image
1725
src={"/ic_medal.svg"}

components/BestArticleSection.module.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929

3030
border-radius: 8px;
3131
background: var(--Cool-Gray-50, #f9fafb);
32+
33+
cursor: pointer;
3234
}
3335

3436
.bestMark {

components/Hearts.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ export default function Hearts({
4848
}
4949

5050
const handleHeartBtn = (e) => {
51+
e.preventDefault();
52+
5153
// 로그인 안하면 좋아요 이용 불가
5254
if (!userId) {
5355
alert("좋아요 기능은 로그인 후 이용할 수 있습니다.");

components/IdArticleContent.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,24 @@ import Image from "next/image";
22
import styles from "./IdArticleContent.module.css";
33
import IcHeart from "@/public/ic_heart.svg";
44

5-
export default function IdArticleContent() {
5+
export default function IdArticleContent({ data }) {
6+
console.log(data);
7+
68
return (
79
<div className={styles.articleContent}>
810
<div className={styles.header}>
911
<div className={styles.titleHeader}>
10-
<div className={styles.title}>{`title`}</div>
12+
<div className={styles.title}>{data.title}</div>
1113
<div className={styles.dropOption}>{`drop option`}</div>
1214
</div>
1315
<div className={styles.info}>
1416
<div className={styles.user}>
15-
<Image />
17+
{/* <Image /> */}
1618
<div className={styles.nickname}>{`user name`}</div>
1719
<div className={styles.date}>{`date`}</div>
1820
</div>
1921
<div className={styles.heart}>
20-
<Image className={styles.heartIc} src={IcHeart} />
22+
{/* <Image className={styles.heartIc} src={IcHeart} /> */}
2123
<div className={styles.heartCount}>{`heart count`}</div>
2224
</div>
2325
</div>

pages/article/[id].js

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,43 @@ import IdArticleContent from "@/components/IdArticleContent";
22
import CommentInput from "@/components/CommentInput";
33
import CommentList from "@/components/CommentList";
44
import CustomButtonSquare from "@/components/CustomButtonSquare";
5+
import { useRouter } from "next/router";
6+
import { useEffect, useState } from "react";
7+
import axios from "axios";
58

69
export default function ArticleId() {
10+
const [isLoading, setIsLoading] = useState(false);
11+
const [article, setArticle] = useState({});
12+
const router = useRouter();
13+
const { id } = router.query;
14+
15+
useEffect(() => {
16+
async function getArticleById(id) {
17+
setIsLoading(true);
18+
if (id) {
19+
try {
20+
const res = await axios.get(`http://localhost:5000/article/${id}`);
21+
setArticle(res.data);
22+
console.log(res.data);
23+
} catch (e) {
24+
console.error(e);
25+
} finally {
26+
setIsLoading(false);
27+
}
28+
}
29+
}
30+
31+
getArticleById(id);
32+
}, [id]);
33+
34+
if (isLoading) {
35+
return <div>로딩 중...</div>;
36+
}
37+
738
return (
839
<>
940
<div>
10-
<IdArticleContent />
41+
<IdArticleContent data={article} />
1142
<CommentInput />
1243
<CommentList />
1344
</div>

0 commit comments

Comments
 (0)