Skip to content

Commit

Permalink
Merge branch 'comment/#113' into comment/113
Browse files Browse the repository at this point in the history
  • Loading branch information
Brokyeom committed Jul 20, 2022
2 parents d0a3f4e + 365a262 commit b23962c
Show file tree
Hide file tree
Showing 11 changed files with 129 additions and 46 deletions.
2 changes: 1 addition & 1 deletion components/common/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default function Header() {
</p>
</StTopLink>
<StHeaderContents>
<Link href="/main">
<Link href="/">
<a>
<IcNoriHeaderLogo />
</a>
Expand Down
1 change: 1 addition & 0 deletions components/community/CommunityList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default function CommunityList(props: CommunityListProps) {
<StCommunityListWrapper>
{contentsList.map((content, idx) => (
<ContentCard
id={content.id}
key={idx}
category={content.category}
title={content.title}
Expand Down
33 changes: 27 additions & 6 deletions components/community/ContentsCard.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import styled from '@emotion/styled';
import { IcReply, IcHeart, IcDot } from '../../public/assets/icons';
import CommunityCategory from './CommunityCategory';
import Router from 'next/router';
import { useRouter } from 'next/router';
import Link from 'next/link';

interface ContentInfoProps {
id: string;
category: string;
title: string;
content: string;
Expand All @@ -13,15 +17,27 @@ interface ContentInfoProps {
}

export default function ContentCard(props: ContentInfoProps) {
const { category, title, content, userNickname, replyCount, createdAt, img } =
props;
const {
id,
category,
title,
content,
userNickname,
replyCount,
createdAt,
img,
} = props;

return (
<StContentsCardWrapper>
<StContentInfo>
<CommunityCategory category={category} />
<h1>{title}</h1>
<p>{content}</p>
<StMainInfo
onClick={() => Router.push({ pathname: `/community/${id}` })}
>
<h1>{title}</h1>
<p>{content}</p>
</StMainInfo>
<StWriteInfo>
<span>{userNickname}</span>
<IcDot />
Expand Down Expand Up @@ -56,6 +72,8 @@ const StContentsCardWrapper = styled.div`
margin-bottom: 0.7rem;
${({ theme }) => theme.fonts.b9_24_medium_150}
cursor: pointer;
}
p {
Expand All @@ -68,8 +86,11 @@ const StContentsCardWrapper = styled.div`
color: ${({ theme }) => theme.colors.gray009};
${({ theme }) => theme.fonts.t6_17_regular_140}
cursor: pointer;
}
`;
const StMainInfo = styled.article``;
const StContentInfo = styled.section`
margin-right: 4.9rem;
Expand All @@ -79,10 +100,10 @@ const StContentImg = styled.img`
width: 21.6rem;
height: 21.6rem;
object-fit: cover;
border: 0.1rem solid ${({ theme }) => theme.colors.gray005};
border-radius: 0.5rem;
object-fit: cover;
`;
const StWriteInfo = styled.div`
display: flex;
Expand Down
11 changes: 9 additions & 2 deletions components/community/ReplyContent.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
import styled from '@emotion/styled';
import { IcReplyWriteIcon } from '../../public/assets/icons';
import { useState } from 'react';

interface ReplyContentProps {
author: boolean;
userNickname?: string;
content: string;
createdAt: string;
}

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

return (
<StReplyContentWrapper>
<StReplyInfo>
<p>{userNickname}</p>
{author && <IcReplyWriteIcon />}
</StReplyInfo>
<StReplyContents>
<p>{content}</p>
<span>{createdAt} ยท ์‹ ๊ณ </span>
<span>
{createdAt} ยท {author ? '์‚ญ์ œ' : '์‹ ๊ณ '}
</span>
</StReplyContents>
</StReplyContentWrapper>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,55 @@
import styled from '@emotion/styled';
import ReplyContent from '../community/ReplyContent';
import { useState } from 'react';
import { useState, useEffect } from 'react';
import { postReply } from '../../core/api/community';
import {
CommunityData,
PostCommentBody,
ReplyData,
} from '../../types/community';
import ReplyContent from './ReplyContent';
import { useRouter } from 'next/router';

interface ReplyListProps {
cid: string;
replyList: ReplyData[];
}

export default function Reply() {
export default function ReplyList(props: ReplyListProps) {
const router = useRouter();
const { replyList, cid } = props;
const [inputColor, setInputColor] = useState<boolean>(false);
const [replyText, setReplyText] = useState<string>('');
const [newReplyInfo, setNewReplyInfo] = useState<PostCommentBody>({
boardId: '',
content: '',
});

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

const handleInputColor = () => {
setInputColor(replyText.length !== 0);
};

const handleReplyregister = async () => {
const { content } = newReplyInfo;
if (content === '') {
alert('๋‚ด์šฉ์„ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š”.');
return;
}

const data = await postReply(newReplyInfo);
setNewReplyInfo({
boardId: `${cid}`,
content: replyText,
});
router.push(`/community/${data.id}`);
};

return (
<StReplyWrapper>
<>
<StReplyTitle>
<h1>๋Œ“๊ธ€</h1>
<p>23</p>
Expand All @@ -29,37 +63,25 @@ export default function Reply() {
onChange={handleInputText}
/>
</StInputContent>
<StInputBtn inputColor={inputColor}>์ž…๋ ฅ</StInputBtn>
<StInputBtn inputColor={inputColor} onClick={handleReplyregister}>
์ž…๋ ฅ
</StInputBtn>
</StInputForm>
<ReplyContent
userNickname="ํฌ์ง€๋ง˜"
createdAt="2022.07.13"
content="์ €ํฌ๋Š” 4๊ฐœ์›” ๋•Œ๋ถ€ํ„ฐ ํ•™์Šต์šฉ ์™„๊ตฌ ์ผ์–ด์š”!"
/>
<ReplyContent
userNickname="ํฌ์ง€๋ง˜"
createdAt="2022.07.13"
content="์ €ํฌ๋Š” 4๊ฐœ์›” ๋•Œ๋ถ€ํ„ฐ ํ•™์Šต์šฉ ์™„๊ตฌ ์ผ์–ด์š”!"
/>
<ReplyContent
userNickname="ํฌ์ง€๋ง˜"
createdAt="2022.07.13"
content="์ €ํฌ๋Š” 4๊ฐœ์›” ๋•Œ๋ถ€ํ„ฐ ํ•™์Šต์šฉ ์™„๊ตฌ ์ผ์–ด์š”!"
/>
<ReplyContent
userNickname="ํฌ์ง€๋ง˜"
createdAt="2022.07.13"
content="์ €ํฌ๋Š” 4๊ฐœ์›” ๋•Œ๋ถ€ํ„ฐ ํ•™์Šต์šฉ ์™„๊ตฌ ์ผ์–ด์š”!"
/>
</StReplyWrapper>
<StReplyWrapper>
{replyList.map((reply, idx) => (
<ReplyContent
key={idx}
author={reply.author}
userNickname={reply.userNickname}
content={reply.content}
createdAt={reply.createdAt}
/>
))}
</StReplyWrapper>
</>
);
}

const StReplyWrapper = styled.section`
display: flex;
flex-direction: column;
justify-content: flex-start;
`;
const StReplyTitle = styled.article`
display: flex;
flex-direction: row;
Expand Down Expand Up @@ -136,3 +158,8 @@ const StInputBtn = styled.span<{ inputColor: boolean }>`
cursor: pointer;
`;
const StReplyWrapper = styled.section`
display: flex;
flex-direction: column;
justify-content: flex-start;
`;
2 changes: 1 addition & 1 deletion components/community/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export { default as ReplyContent } from './ReplyContent';
export { default as CommunityList } from './CommunityList';
export { default as Reply } from './Reply';
export { default as CommunityFloatingBtn } from './CommunityFloatingBtn';
export { default as replyList } from './ReplyList';
11 changes: 10 additions & 1 deletion core/api/community.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import useSWR from 'swr';
import { PostCommunityBody } from '../../types/community';
import { PostCommentBody, PostCommunityBody } from '../../types/community';
import { baseInstance } from '../axios';

export const useGetCollectionProduct = (key: string) => {
Expand Down Expand Up @@ -47,3 +47,12 @@ export const deleteCommunity = async (id: string) => {
console.log(e);
}
};

export const postReply = async (body: PostCommentBody) => {
try {
const { data } = await baseInstance.post('/board/comment', body);
return data;
} catch (e) {
console.log(e);
}
};
16 changes: 14 additions & 2 deletions pages/community/[cid].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import Link from 'next/link';
import { useRouter } from 'next/router';
import { ParsedUrlQuery } from 'querystring';
import { useState } from 'react';
import { Reply } from '../../components/community';
import CommunityCategory from '../../components/community/CommunityCategory';
import DetailFloatingBtn from '../../components/community/DetailFloatingBtn';
import ReplyList from '../../components/community/ReplyList';
import { deleteCommunity, getCommunityDetail } from '../../core/api/community';
import { IcExpandImg, IcMenu, IcWriter } from '../../public/assets/icons';
import { CommunityData } from '../../types/community';
Expand Down Expand Up @@ -109,7 +109,7 @@ export default function CommunityDetail({
</StCommunityContent>
</StCommunityArticle>
</StCommunitySection>
<Reply />
<ReplyList replyList={replyList} cid={cid} />
</StDetailSection>
<DetailFloatingBtn heartNum={0} replyNum={replyCount} />
{isExpanded && (
Expand Down Expand Up @@ -156,61 +156,73 @@ export const getServerSideProps: GetServerSideProps<Props, Params> = async ({
userNickname: 'ํฌ์ง€๋ง˜',
content: '์™€ ์ •๋ง ์ข‹์€ ๊ธ€ ์ž…๋‹ˆ๋‹ค.',
createdAt: '2022.06.23',
author: true,
},
{
userNickname: 'ํฌ์ง€๋ง˜',
content: '์™€ ์ •๋ง ๊ณต๊ฐ๊ฐ€๋Š” ๊ธ€ ์ž…๋‹ˆ๋‹ค.',
createdAt: '2022.06.23',
author: false,
},
{
userNickname: 'ํฌ์ง€๋ง˜',
content: '์™€ ์ •๋ง ์ข‹์€ ๊ธ€ ์ž…๋‹ˆ๋‹ค.',
createdAt: '2022.06.23',
author: false,
},
{
userNickname: 'ํฌ์ง€๋ง˜',
content: '์™€ ์ •๋ง ๊ณต๊ฐ๊ฐ€๋Š” ๊ธ€ ์ž…๋‹ˆ๋‹ค.',
createdAt: '2022.06.23',
author: true,
},
{
userNickname: 'ํฌ์ง€๋ง˜',
content: '์™€ ์ •๋ง ์ข‹์€ ๊ธ€ ์ž…๋‹ˆ๋‹ค.',
createdAt: '2022.06.23',
author: true,
},
{
userNickname: 'ํฌ์ง€๋ง˜',
content: '์™€ ์ •๋ง ๊ณต๊ฐ๊ฐ€๋Š” ๊ธ€ ์ž…๋‹ˆ๋‹ค.',
createdAt: '2022.06.23',
author: false,
},
{
userNickname: 'ํฌ์ง€๋ง˜',
content: '์™€ ์ •๋ง ์ข‹์€ ๊ธ€ ์ž…๋‹ˆ๋‹ค.',
createdAt: '2022.06.23',
author: true,
},
{
userNickname: 'ํฌ์ง€๋ง˜',
content: '์™€ ์ •๋ง ๊ณต๊ฐ๊ฐ€๋Š” ๊ธ€ ์ž…๋‹ˆ๋‹ค.',
createdAt: '2022.06.23',
author: false,
},
{
userNickname: 'ํฌ์ง€๋ง˜',
content: '์™€ ์ •๋ง ์ข‹์€ ๊ธ€ ์ž…๋‹ˆ๋‹ค.',
createdAt: '2022.06.23',
author: true,
},
{
userNickname: 'ํฌ์ง€๋ง˜',
content: '์™€ ์ •๋ง ๊ณต๊ฐ๊ฐ€๋Š” ๊ธ€ ์ž…๋‹ˆ๋‹ค.',
createdAt: '2022.06.23',
author: false,
},
{
userNickname: 'ํฌ์ง€๋ง˜',
content: '์™€ ์ •๋ง ์ข‹์€ ๊ธ€ ์ž…๋‹ˆ๋‹ค.',
createdAt: '2022.06.23',
author: true,
},
{
userNickname: 'ํฌ์ง€๋ง˜',
content: '์™€ ์ •๋ง ๊ณต๊ฐ๊ฐ€๋Š” ๊ธ€ ์ž…๋‹ˆ๋‹ค.',
createdAt: '2022.06.23',
author: false,
},
],
},
Expand Down
1 change: 1 addition & 0 deletions public/assets/icons/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ export { default as IcGoogleBtn } from './btn_social_login_google.svg';
export { default as IcNaverBtn } from './btn_social_login_naver.svg';
export { default as IcSignupCheckboxUnselected } from './ic_checkbox_unselected_black_20.svg';
export { default as IcSignupCheckboxSelected } from './ic_checkbox_selected_green_20.svg';
export { default as IcReplyWriteIcon } from './replyWriterIcon.svg';
4 changes: 4 additions & 0 deletions public/assets/icons/replyWriterIcon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit b23962c

Please sign in to comment.