-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from TripMingle/feat/SWM-264
[feat/SWM-264] 정보글 상세보기 페이지 개발
- Loading branch information
Showing
19 changed files
with
344 additions
and
38 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import Image from 'next/image'; | ||
import '@/styles/font.css'; | ||
import Header from '@/components/header/Header'; | ||
import * as styles from '@/styles/country/board/id/page.css'; | ||
import TravelerCard from '@/components/country/board/id/TravelerCard'; | ||
import CommentInput from '@/components/common/CommentInput'; | ||
import CommentList from '@/components/country/post/id/CommentList'; | ||
import { headers } from 'next/headers'; | ||
import { PostDetailType } from '@/types/country/post'; | ||
import Like from '@/components/country/post/id/Like'; | ||
|
||
const Page = async ({ | ||
params, | ||
}: { | ||
params: { country: string; id: string }; | ||
}) => { | ||
console.log(params); | ||
const headersList = headers(); | ||
const host = headersList.get('host'); | ||
const protocol = process.env.NODE_ENV === 'production' ? 'https' : 'http'; | ||
|
||
const postData = await fetch( | ||
`${protocol}://${host}/api/post?postId=${params.id}`, | ||
).then((res) => res.json()); | ||
|
||
const postDetail: PostDetailType = postData.data; | ||
|
||
return ( | ||
<main> | ||
<Header /> | ||
<div className={styles.pageContainer}> | ||
<div className={styles.container}> | ||
<div className={styles.contentContainer}> | ||
<p className={styles.title}>{postDetail.title}</p> | ||
<div> | ||
<Like | ||
isLike={postDetail.myLikeState} | ||
likeCount={postDetail.likeCount} | ||
/> | ||
<span className={styles.iconContainer}> | ||
<Image | ||
className={styles.icon} | ||
src="/icons/comment.svg" | ||
width={20} | ||
height={20} | ||
alt="commendIcon" | ||
/> | ||
<span>{postDetail.commentCount}</span> | ||
</span> | ||
</div> | ||
<div className={styles.infoContainer}> | ||
<p className={styles.infoTitle}>내용</p> | ||
<div className={styles.infoContent}>{postDetail.content}</div> | ||
</div> | ||
</div> | ||
<TravelerCard | ||
props={{ | ||
userImageUrl: postDetail.userImageUrl, | ||
nickName: postDetail.userNickName, | ||
userId: 0, | ||
ageRange: postDetail.userAgeRange, | ||
gender: postDetail.userGender, | ||
nationality: postDetail.userNationality, | ||
selfIntroduction: postDetail.selfIntroduce ?? '', | ||
}} | ||
title="작성자" | ||
type="post" | ||
/> | ||
</div> | ||
<div className={styles.container}> | ||
<div className={styles.commentContainer}> | ||
<p className={styles.commentTitle}> | ||
{'댓글 '} | ||
<strong className={styles.commentTitleStrong}> | ||
{postDetail.commentCount} | ||
</strong> | ||
{' 개'} | ||
</p> | ||
<CommentInput id={postDetail.postingId} type="post" /> | ||
<CommentList comments={postDetail.postingComments} /> | ||
</div> | ||
</div> | ||
</div> | ||
</main> | ||
); | ||
}; | ||
|
||
export default Page; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { getAccessToken } from '@/utils/server/token'; | ||
import { NextRequest, NextResponse } from 'next/server'; | ||
|
||
export const POST = async (req: NextRequest) => { | ||
const baseurl = `${process.env.API_URL}`; | ||
const pathname = `/postings`; | ||
const body = req.body; | ||
const postId = req.nextUrl.searchParams.get('postId'); | ||
|
||
let token = await getAccessToken(); | ||
if (!token) | ||
return NextResponse.json( | ||
{ error: 'access token이 없거나 만료되었습니다.' }, | ||
{ status: 500 }, | ||
); | ||
console.log(`${baseurl}${pathname}/${postId}/comments`); | ||
|
||
return await fetch(`${baseurl}${pathname}/${postId}/comments`, { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: `Bearer ${token.value}`, | ||
}, | ||
body, | ||
// @ts-ignore -- 연결이 단방향임을 나타냄 | ||
duplex: 'half', | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { PostPreviewProps } from '@/types/country/post'; | ||
import Profile from '@/components/common/Profile'; | ||
import * as styles from '@/styles/country/post/page.css'; | ||
import { usePathname, useRouter } from 'next/navigation'; | ||
|
||
// postcard와 css가 다름 | ||
const PostCardListItem = ({ props }: { props: PostPreviewProps }) => { | ||
const router = useRouter(); | ||
const pathname = usePathname(); | ||
|
||
const clickHandler = async () => { | ||
router.push(pathname + `/${props.postingId}`); | ||
}; | ||
|
||
return ( | ||
<div className={styles.postCard} onClick={clickHandler}> | ||
<span className={styles.title}>{props.title}</span> | ||
<span className={styles.content}>{props.content}</span> | ||
<div className={styles.profileContainer}> | ||
<Profile | ||
url={props.userImageUrl} | ||
width={18} | ||
height={18} | ||
changeWidth={24} | ||
changeHeight={24} | ||
/> | ||
<span className={styles.profileInfo}> | ||
{`${props.userNickName} · ${props.userAgeRange.slice(0, 2)}대 · | ||
${props.userGender === 'male' ? '남' : '여'} · ${props.userNationality}`} | ||
</span> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default PostCardListItem; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import * as styles from '@/styles/components/common/comment.css'; | ||
import Profile from '@/components/common/Profile'; | ||
import { formatDate } from '@/utils/date'; | ||
import { PostCommentType } from '@/types/country/post'; | ||
|
||
const Comment = ({ props }: { props: PostCommentType }) => { | ||
return ( | ||
<div className={styles.commentContainer}> | ||
<Profile | ||
url={props.userImageUrl} | ||
width={30} | ||
height={30} | ||
changeWidth={36} | ||
changeHeight={36} | ||
/> | ||
<div className={styles.contentContainer}> | ||
<div className={styles.infoContainer}> | ||
<span className={styles.name}>{props.userNickName}</span> | ||
<span className={styles.time}>{formatDate(props.createdAt)}</span> | ||
</div> | ||
<p className={styles.content}>{props.comment}</p> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default Comment; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import Comment from './Comment'; | ||
import { commentListContainer } from '@/styles/components/common/comment.css'; | ||
import { PostCommentType } from '@/types/country/post'; | ||
|
||
const CommentList = ({ comments }: { comments: PostCommentType[] }) => { | ||
return ( | ||
<ul className={commentListContainer}> | ||
{comments.map((comment) => ( | ||
<li key={comment.commentId}> | ||
<Comment props={comment} /> | ||
</li> | ||
))} | ||
</ul> | ||
); | ||
}; | ||
|
||
export default CommentList; |
Oops, something went wrong.