Skip to content
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

[ CommunityForm ] 댓글 POST 연결 #149

Merged
merged 25 commits into from
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
f26c3ff
[ chore ] img 연산자 코드 변경
Brokyeom Jul 21, 2022
c0bfb19
Merge branch 'develop' of https://github.com/nori-dongsan/nori-client…
Brokyeom Jul 21, 2022
4915278
Merge branch 'develop' into comment/#138
Brokyeom Jul 21, 2022
66c01c5
Merge branch 'develop' of https://github.com/nori-dongsan/nori-client…
Brokyeom Jul 21, 2022
50464ee
Merge branch 'develop' into comment/#138
Brokyeom Jul 21, 2022
c7f959c
Merge branch 'develop' of https://github.com/nori-dongsan/nori-client…
Brokyeom Jul 21, 2022
d43fb50
Merge branch 'develop' of https://github.com/nori-dongsan/nori-client…
Brokyeom Jul 21, 2022
1293364
Merge branch 'develop' into feature-community
Brokyeom Jul 21, 2022
8949c4d
Merge branch 'develop' of https://github.com/nori-dongsan/nori-client…
Brokyeom Jul 21, 2022
6960398
Merge branch 'develop' into feature-community
Brokyeom Jul 21, 2022
ae6044c
Merge branch 'feature-community' into comment/#138
Brokyeom Jul 21, 2022
49bd064
[ chore ] 단순 코드 수정
Brokyeom Jul 21, 2022
6a6abff
[ chore ] 단순 코드 수정
Brokyeom Jul 21, 2022
a484b1c
Merge branch 'feature-community' of https://github.com/nori-dongsan/n…
Brokyeom Jul 21, 2022
35321c1
Merge branch 'feature-community' into comment/#138
Brokyeom Jul 21, 2022
79336dd
Merge branch 'develop' of https://github.com/nori-dongsan/nori-client…
Brokyeom Jul 21, 2022
b089337
Merge branch 'feature-community' into comment/#138
Brokyeom Jul 21, 2022
45a0f7d
[ feat ] 댓글 post 연결
Brokyeom Jul 21, 2022
dd7bcd6
[ style ] 이미지 유무에 따른 width 조절
Brokyeom Jul 21, 2022
6285093
Merge branch 'comment/#138' of https://github.com/nori-dongsan/nori-c…
Brokyeom Jul 21, 2022
af6fbe1
Merge branch 'feature-community' into comment/#138
Brokyeom Jul 21, 2022
af7fea7
Merge branch 'feature-community' of https://github.com/nori-dongsan/n…
Brokyeom Jul 21, 2022
4a360d5
Merge branch 'feature-community' into comment/#138
Brokyeom Jul 21, 2022
8d4f9c8
Merge branch 'comment/#138' of https://github.com/nori-dongsan/nori-c…
Brokyeom Jul 21, 2022
e9412c2
Merge branch 'feature-community' into comment/#138
aeuna Jul 21, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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