-
Notifications
You must be signed in to change notification settings - Fork 0
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
[#145] 커뮤니티 api 연결, 반응형으로 수정 #163
Changes from 6 commits
ffb600b
6cb962d
0aeb88e
bd41175
61fa424
7be564c
e016420
2312306
216f4b8
a9a836b
14550c5
02ee8da
6c60f17
f4bc423
ac0d2f0
e465b94
7d2514b
8819bd4
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 |
---|---|---|
|
@@ -4,8 +4,6 @@ import Image from 'next/image'; | |
import Comment from '@/components/common/Comment'; | ||
import CommentInput from '@/components/common/Comment/CommentInput'; | ||
import Category from '@/components/common/Category'; | ||
import Sue from '@icons/icon/Icon18/Sue.svg'; | ||
import Ben from '@icons/icon/Icon18/Ben.svg'; | ||
import SamllHits from '@icons/icon/Icon18/SmallHits.svg'; | ||
import FilledLiked from '@icons/icon/Liked/FilledLiked.svg'; | ||
import DefaultLiked from '@icons/icon/Liked/DefaultLiked.svg'; | ||
|
@@ -15,11 +13,16 @@ import DefaultScrap from '@icons/icon/Scrap/DefaultScrap.svg'; | |
import { | ||
getCommunityInfoAPI, | ||
getCommunityInfoCommentAPI, | ||
postCommunityDislikeAPI, | ||
postCommunityLikeAPI, | ||
postCommunityScrapAPI, | ||
} from '@/apis/communityAPIS'; | ||
import { useRouter } from 'next/router'; | ||
import { Comments, NoticeInfoProps } from '@/types/NoticeFunsystem'; | ||
import { Comments } from '@/types/NoticeFunsystem'; | ||
import UtilityHeader from '@/components/common/Header/UtilityHeader'; | ||
import { CommunityInfoProps } from '@/types/Community'; | ||
const CommunityInfo = () => { | ||
const [data, setData] = useState<CommunityInfoProps>(); | ||
const [comments, setComments] = useState<Comments[]>(); | ||
const [isLike, setIsLike] = useState<boolean>(false); | ||
const [isScrap, setIsScrap] = useState<boolean>(false); | ||
|
@@ -28,19 +31,44 @@ const CommunityInfo = () => { | |
setMenu(!menu); | ||
}; | ||
|
||
// 현재 주소 값 | ||
const router = useRouter(); | ||
const path = router.asPath; | ||
const pathId = router.query.id; | ||
|
||
const handleLikeClick = () => { | ||
setIsLike(!isLike); | ||
if (!isLike) { | ||
postCommunityLikeAPI(Number(pathId)); | ||
} else { | ||
postCommunityDislikeAPI(Number(pathId)); | ||
} | ||
}; | ||
|
||
const handleScrapClick = () => { | ||
setIsScrap(!isScrap); | ||
if (!isScrap) { | ||
postCommunityScrapAPI(Number(pathId), !isScrap); | ||
} | ||
}; | ||
|
||
useEffect(() => { | ||
const getCommunityInfo = getCommunityInfoAPI(Number(pathId)); | ||
getCommunityInfo.then((res) => { | ||
setData(res.data); | ||
}); | ||
|
||
const getcomments = getCommunityInfoCommentAPI(Number(pathId)); | ||
getcomments.then((res) => { | ||
setComments(res?.data); | ||
}); | ||
}, []); | ||
|
||
return ( | ||
<styles.Container> | ||
<UtilityHeader child="커뮤니티" isCommunity={true} /> | ||
<styles.InfoBox> | ||
<Category label="질문" BgColor={false} /> | ||
<Category label={data?.topic} BgColor={false} /> | ||
</styles.InfoBox> | ||
<styles.Padding> | ||
<styles.ProfileBox> | ||
|
@@ -55,11 +83,11 @@ const CommunityInfo = () => { | |
</styles.ProfileLeftBox> | ||
<styles.ProfileCenterBox> | ||
<styles.ProfileTopBox> | ||
<styles.NickNameBox>닉네임</styles.NickNameBox> | ||
<styles.NickNameBox>{data?.writerNickName}</styles.NickNameBox> | ||
</styles.ProfileTopBox> | ||
<styles.ProfileBottomBox> | ||
<styles.DateBox>2023/05/20</styles.DateBox> | ||
<styles.TimeBox>21:23</styles.TimeBox> | ||
<styles.DateBox>{data?.updatedAt.slice(0, 10)}</styles.DateBox> | ||
<styles.TimeBox>{data?.updatedAt.slice(11, 16)}</styles.TimeBox> | ||
halfmoon-mind marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<styles.ProfileRightBox> | ||
<styles.ViewBox> | ||
<styles.ViewIconBox> | ||
|
@@ -71,17 +99,14 @@ const CommunityInfo = () => { | |
priority | ||
/> | ||
</styles.ViewIconBox> | ||
<styles.ViewCountBox>5회</styles.ViewCountBox> | ||
<styles.ViewCountBox>{data?.views}회</styles.ViewCountBox> | ||
</styles.ViewBox> | ||
</styles.ProfileRightBox> | ||
</styles.ProfileBottomBox> | ||
</styles.ProfileCenterBox> | ||
</styles.ProfileBox> | ||
<styles.TitleBox>이거 어떻게 하는 거예요</styles.TitleBox> | ||
<styles.ContentBox> | ||
엄청나게 잘해서 A+를 받겠어~ 엄청나게 잘해서 A+를 받겠어~ 종강아 | ||
어서와 | ||
</styles.ContentBox> | ||
<styles.TitleBox>{data?.title}</styles.TitleBox> | ||
<styles.ContentBox>{data?.content}</styles.ContentBox> | ||
<styles.UnderBarBox> | ||
<styles.IconCountBox> | ||
<styles.IconBox onClick={handleLikeClick}> | ||
|
@@ -104,7 +129,7 @@ const CommunityInfo = () => { | |
)} | ||
{/** TODO: 눌렀을때 모양 변경 */} | ||
</styles.IconBox> | ||
<styles.CountBox>5</styles.CountBox> | ||
<styles.CountBox>{data?.likes}</styles.CountBox> | ||
</styles.IconCountBox> | ||
<styles.IconCountBox> | ||
<styles.IconBox> | ||
|
@@ -116,7 +141,7 @@ const CommunityInfo = () => { | |
priority | ||
/> | ||
</styles.IconBox> | ||
<styles.CountBox>5</styles.CountBox> | ||
<styles.CountBox>{data?.comments}</styles.CountBox> | ||
</styles.IconCountBox> | ||
<styles.IconCountBox> | ||
<styles.IconBox onClick={handleScrapClick}> | ||
|
@@ -138,13 +163,27 @@ const CommunityInfo = () => { | |
/> | ||
)} | ||
</styles.IconBox> | ||
<styles.CountBox>0</styles.CountBox> | ||
<styles.CountBox>{data?.scrapCount}</styles.CountBox> | ||
</styles.IconCountBox> | ||
</styles.UnderBarBox> | ||
</styles.Padding> | ||
<styles.BottomBox> | ||
<styles.CommentTitleBox>댓글</styles.CommentTitleBox> | ||
</styles.BottomBox> | ||
{comments?.map((comment) => { | ||
return ( | ||
<Comment | ||
key={comment.commentId} | ||
nickname={''} | ||
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. nickname 데이터는 없나요? 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. 네,,,,, 서버에서 userId는 주는데 닉네임을 안줬습니다ㅠㅠ 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. 닉네임 api 변경 요청 해야할 것 같아요! 뷰에서 사용하는데 api에 꼭 필요할 것 같아요! 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. 넵!!! |
||
createdAt={comment.createdAt} | ||
updatedAt={comment.updatedAt} | ||
content={comment.content} | ||
commentId={comment.commentId} | ||
originalCommentId={comment.originalCommentId} | ||
userId={comment.userId} | ||
/> | ||
); | ||
})} | ||
|
||
<CommentInput /> | ||
</styles.Container> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
export interface CommunityInfoProps { | ||
id: number; | ||
title: string; | ||
content: string; | ||
category: string; | ||
imageUrls: string[]; | ||
fileUrl: string; | ||
createdAt: string; | ||
updatedAt: string; | ||
views: number; | ||
comments: number; | ||
likes: number; | ||
scrapCount: number; | ||
topic: string; | ||
writerNickName: string; | ||
} |
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.
요런거 주석처리 해놓는게 좋을거 같아요!