|
| 1 | +'use client'; |
| 2 | + |
| 3 | +import { fetchPostById } from '@/domains/community/api/fetchPost'; |
1 | 4 | import DetailContent from '@/domains/community/detail/DetailContent'; |
2 | 5 | import DetailHeader from '@/domains/community/detail/DetailHeader'; |
3 | 6 | import DetailTitle from '@/domains/community/detail/DetailTitle'; |
4 | 7 | import DetailTabDesktop from '@/domains/community/detail/tab/DetailTabDesktop'; |
5 | | -import Comment from '@/domains/shared/components/comment/Comment'; |
| 8 | +import { Post } from '@/domains/community/types/post'; |
| 9 | +import Comment from '@/domains/community/detail/Comment'; |
6 | 10 | import StarBg from '@/domains/shared/components/star-bg/StarBg'; |
| 11 | +import { useParams } from 'next/navigation'; |
| 12 | +import { useEffect, useState } from 'react'; |
7 | 13 |
|
8 | 14 | function Page() { |
| 15 | + const params = useParams(); |
| 16 | + const [postDetail, setPostDetail] = useState<Post | null>(null); |
| 17 | + |
| 18 | + useEffect(() => { |
| 19 | + const postId = params.id; |
| 20 | + const fetchData = async () => { |
| 21 | + const data = await fetchPostById(postId); |
| 22 | + if (!data) return; |
| 23 | + |
| 24 | + setPostDetail(data); |
| 25 | + }; |
| 26 | + fetchData(); |
| 27 | + }, [params.id, setPostDetail]); |
| 28 | + |
| 29 | + if (!postDetail) return <div>게시글을 불러오지 못했습니다.</div>; |
| 30 | + |
| 31 | + const { |
| 32 | + categoryName, |
| 33 | + title, |
| 34 | + userNickName, |
| 35 | + createdAt, |
| 36 | + viewCount, |
| 37 | + postId, |
| 38 | + tags, |
| 39 | + content, |
| 40 | + likeCount, |
| 41 | + commentCount, |
| 42 | + } = postDetail; |
| 43 | + |
9 | 44 | return ( |
10 | 45 | <div className="w-full relative"> |
11 | 46 | <StarBg className="w-full h-32 absolute"></StarBg> |
12 | 47 | <article className="page-layout max-w-824 z-5"> |
13 | | - <DetailHeader /> |
14 | | - <DetailTitle /> |
15 | | - <DetailContent /> |
| 48 | + <DetailHeader categoryName={categoryName} /> |
| 49 | + <DetailTitle title={title} userNickname={userNickName} /> |
| 50 | + <DetailContent |
| 51 | + content={content} |
| 52 | + createdAt={createdAt} |
| 53 | + viewCount={viewCount} |
| 54 | + postId={postId} |
| 55 | + tags={tags} |
| 56 | + likeCount={likeCount} |
| 57 | + commentCount={commentCount} |
| 58 | + /> |
16 | 59 | <section className="mb-10"> |
17 | | - <Comment /> |
| 60 | + <Comment postId={postId} /> |
18 | 61 | </section> |
19 | 62 | </article> |
20 | 63 | <div className="hidden md:block"> |
21 | | - <DetailTabDesktop /> |
| 64 | + <DetailTabDesktop likeCount={likeCount} commentCount={commentCount} /> |
22 | 65 | </div> |
23 | 66 | </div> |
24 | 67 | ); |
|
0 commit comments