Skip to content

Commit

Permalink
Merge pull request #149 from nori-dongsan/comment/#138
Browse files Browse the repository at this point in the history
[  CommunityForm ] 댓글 POST 연결
  • Loading branch information
aeuna authored Jul 21, 2022
2 parents 182ca8e + e9412c2 commit 6745957
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 39 deletions.
38 changes: 25 additions & 13 deletions components/community/ContentCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ interface ContentInfoProps {
content: string;
userNickname?: string;
replyCount?: number;
createdAt?: string;
createdAt: string;
img?: string;
}

Expand All @@ -30,16 +30,25 @@ export default function ContentCard(props: ContentInfoProps) {
<StContentsCardWrapper>
<StContentInfo>
<CommunityCategory category={category} />
<StMainInfo
onClick={() => Router.push({ pathname: `/community/${id}` })}
>
<h1>{title}</h1>
<p>{content}</p>
</StMainInfo>
{!img ? (
<StMainInfo
onClick={() => Router.push({ pathname: `/community/${id}` })}
>
<h1>{title}</h1>
<p>{content}</p>
</StMainInfo>
) : (
<StImgMainInfo
onClick={() => Router.push({ pathname: `/community/${id}` })}
>
<h1>{title}</h1>
<p>{content}</p>
</StImgMainInfo>
)}
<StWriteInfo>
<span>{userNickname}</span>
<IcDot />
<span>{createdAt?.split('T')[0]}</span>
<span>{createdAt.split('T')[0]}</span>
</StWriteInfo>
<StReplyInfo>
<IcHeart />
Expand All @@ -48,9 +57,7 @@ export default function ContentCard(props: ContentInfoProps) {
<span>{replyCount}</span>
</StReplyInfo>
</StContentInfo>
{img === undefined ? (
<></>
) : (
{img && (
<StContentImg
src={'https://nori-community.s3.ap-northeast-2.amazonaws.com/' + img}
alt="리뷰 사진"
Expand All @@ -72,7 +79,6 @@ const StContentsCardWrapper = styled.div`
border-bottom: 0.1rem solid ${({ theme }) => theme.colors.gray005};
h1 {
width: 92.3rem;
margin-top: 1.6rem;
margin-bottom: 0.7rem;
Expand All @@ -95,7 +101,13 @@ const StContentsCardWrapper = styled.div`
cursor: pointer;
}
`;
const StMainInfo = styled.article``;
const StMainInfo = styled.article`
width: 97.6rem;
`;
const StImgMainInfo = styled.article`
width: 72.5rem;
margin-right: 3.3rem;
`;
const StContentInfo = styled.section`
display: flex;
flex-direction: column;
Expand Down
6 changes: 3 additions & 3 deletions components/community/ReplyContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ interface ReplyContentProps {
author: boolean;
userNickname?: string;
content: string;
createdAt: string;
createAt: string;
}

export default function ReplyContent(props: ReplyContentProps) {
const { userNickname, content, createdAt, author } = props;
const { userNickname, content, createAt, author } = props;

return (
<StReplyContentWrapper>
Expand All @@ -21,7 +21,7 @@ export default function ReplyContent(props: ReplyContentProps) {
<StReplyContents>
<p>{content}</p>
<span>
{createdAt} · {author ? '삭제' : '신고'}
{createAt.split('T')[0]} · {author ? '삭제' : '신고'}
</span>
</StReplyContents>
</StReplyContentWrapper>
Expand Down
38 changes: 18 additions & 20 deletions components/community/ReplyList.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import styled from '@emotion/styled';
import { useState, useEffect } from 'react';
import { useState, useEffect, InputHTMLAttributes } from 'react';
import { postReply } from '../../core/api/community';
import {
CommunityData,
Expand Down Expand Up @@ -29,12 +29,11 @@ export default function ReplyList(props: ReplyListProps) {
const [isFirst, setIsFirst] = useState<boolean>(true);

const handleInputText = (e: React.ChangeEvent<HTMLInputElement>) => {
setReplyText(e.target.value);
setNewReplyInfo({ ...newReplyInfo, content: e.target.value });
setNewReplyInfo({ boardId: cid, content: e.target.value });
};

const handleInputColor = () => {
setInputColor(replyText.length !== 0);
const handleInputColor = (e: any) => {
setInputColor(e.target.value.length !== 0);
};

const handleReplyregister = async () => {
Expand All @@ -44,12 +43,13 @@ export default function ReplyList(props: ReplyListProps) {
return;
}

const data = await postReply(newReplyInfo);
const status = await postReply(newReplyInfo);
setNewReplyInfo({
boardId: `${cid}`,
boardId: cid,
content: replyText,
});
router.push(`/community/${data.id}`);
if (status === 200) router.push(`/community/${cid}`);
setNewReplyInfo({ boardId: cid, content: '' });
};
const handleCurrentPage = (nextPage: number) => {
setCurrentPage(nextPage);
Expand Down Expand Up @@ -89,20 +89,18 @@ export default function ReplyList(props: ReplyListProps) {
</StInputBtn>
</StInputForm>
<StReplyWrapper>
{pageReplyList.map(
({ author, userNickname, content, createdAt }, idx) => (
<ReplyContent
key={idx}
author={author}
userNickname={userNickname}
content={content}
createdAt={createdAt}
/>
),
)}
{replyList.map(({ author, userNickname, content, createAt }, idx) => (
<ReplyContent
key={idx}
author={author}
userNickname={userNickname}
content={content}
createAt={createAt}
/>
))}
</StReplyWrapper>
<StReplyListNav>
{replyList && (
{pageReplyList && (
<PageNavigation
currentPage={currentPage}
lastPage={Math.ceil(replyList.length / 10)}
Expand Down
4 changes: 2 additions & 2 deletions core/api/community.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ export const putCommunity = async (id: string, body: PutCommunityBody) => {

export const postReply = async (body: PostCommentBody) => {
try {
const { data } = await baseInstance.post('/board/comment', body);
return data;
const { status } = await baseInstance.post('/board/comment', body);
return status;
} catch (e) {
console.log(e);
}
Expand Down
5 changes: 4 additions & 1 deletion types/community.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export interface ReplyData {
author: boolean;
userNickname?: string;
content: string;
createdAt: string;
createAt: string;
}
// 커뮤니티 데이터
export interface CommunityData {
Expand All @@ -26,6 +26,7 @@ export interface PostCommunityBody {
content: string;
imageList?: ImgData[];
}

// 커뮤니티 수정 put body
export interface PutCommunityBody {
category?: string;
Expand All @@ -40,11 +41,13 @@ export interface IsChangeCommunity {
isChangeContent: boolean;
isChangeImageList: boolean;
}

// 커뮤니티 댓글
export interface PostCommentBody {
boardId?: string;
content: string;
}

export interface GetCommunityList {
communityList: CommunityData[];
isLoading: boolean;
Expand Down

0 comments on commit 6745957

Please sign in to comment.