File tree Expand file tree Collapse file tree 7 files changed +62
-8
lines changed
Expand file tree Collapse file tree 7 files changed +62
-8
lines changed Original file line number Diff line number Diff line change 11import Image from "next/image" ;
22import styles from "./ArticleItem.module.css" ;
33import Hearts from "./Hearts" ;
4+ import { useRouter } from "next/router" ;
45
56export 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 } />
Original file line number Diff line number Diff line change 88 gap : 16px ;
99
1010 border-bottom : var (--Cool-Gray-200 , # e5e7eb ) solid 1px ;
11+
12+ cursor : pointer;
1113}
1214
1315.content {
Original file line number Diff line number Diff line change @@ -4,14 +4,22 @@ import axios from "axios";
44import { useEffect , useState } from "react" ;
55import styles from "./BestArticleSection.module.css" ;
66import Hearts from "./Hearts" ;
7+ import { useRouter } from "next/router" ;
78
89function 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" }
Original file line number Diff line number Diff line change 2929
3030 border-radius : 8px ;
3131 background : var (--Cool-Gray-50 , # f9fafb );
32+
33+ cursor : pointer;
3234}
3335
3436.bestMark {
Original file line number Diff line number Diff 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 ( "좋아요 기능은 로그인 후 이용할 수 있습니다." ) ;
Original file line number Diff line number Diff line change @@ -2,22 +2,24 @@ import Image from "next/image";
22import styles from "./IdArticleContent.module.css" ;
33import 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 >
Original file line number Diff line number Diff line change @@ -2,12 +2,43 @@ import IdArticleContent from "@/components/IdArticleContent";
22import CommentInput from "@/components/CommentInput" ;
33import CommentList from "@/components/CommentList" ;
44import CustomButtonSquare from "@/components/CustomButtonSquare" ;
5+ import { useRouter } from "next/router" ;
6+ import { useEffect , useState } from "react" ;
7+ import axios from "axios" ;
58
69export 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 >
You can’t perform that action at this time.
0 commit comments