Skip to content

Commit

Permalink
Merge branch 'feature-community' into comment/#138
Browse files Browse the repository at this point in the history
  • Loading branch information
Brokyeom committed Jul 21, 2022
2 parents 6a6abff + a484b1c commit 35321c1
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 43 deletions.
4 changes: 1 addition & 3 deletions components/community/ContentCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ 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;
Expand Down Expand Up @@ -41,7 +39,7 @@ export default function ContentCard(props: ContentInfoProps) {
<StWriteInfo>
<span>{userNickname}</span>
<IcDot />
<span>{createdAt.split('T')[0]}</span>
<span>{createdAt?.split('T')[0]}</span>
</StWriteInfo>
<StReplyInfo>
<IcHeart />
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} · {author ? '삭제' : '신고'}
</span>
</StReplyContents>
</StReplyContentWrapper>
Expand Down
44 changes: 25 additions & 19 deletions components/community/ReplyList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export default function ReplyList(props: ReplyListProps) {
});
const [currentPage, setCurrentPage] = useState<number>(1);
const [pageReplyList, setPageReplyList] = useState<ReplyData[]>([]);
const [isFirst, setIsFirst] = useState<boolean>(true);

console.log('=========================');
console.log(replyList);

const handleInputText = (e: React.ChangeEvent<HTMLInputElement>) => {
setReplyText(e.target.value);
Expand Down Expand Up @@ -55,13 +59,17 @@ export default function ReplyList(props: ReplyListProps) {
};

useEffect(() => {
if (replyList) {
setPageReplyList(
replyList.filter(
(_, idx) => (currentPage - 1) * 10 <= idx && idx < currentPage * 10,
),
);
window.scrollTo({ top: 750 });
if (!isFirst) {
if (replyList) {
setPageReplyList(
replyList.filter(
(_, idx) => (currentPage - 1) * 10 <= idx && idx < currentPage * 10,
),
);
window.scrollTo({ top: 750 });
}
} else {
setIsFirst((prev) => !prev);
}
}, [replyList, currentPage]);
return (
Expand All @@ -84,20 +92,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
2 changes: 1 addition & 1 deletion core/axios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ baseInstance.interceptors.request.use((config) => {
const headers = {
...config.headers,
accessToken:
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MzAsImlhdCI6MTY1ODM5MjA1NCwiZXhwIjoxNjU4Mzk5MjU0LCJpc3MiOiJub3JpIn0.-4zFiA6OVE5L86D0LWyEkyKf7RKvm7qlOG5NWCXcSYM',
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MzAsImlhdCI6MTY1ODQwNzIwMiwiZXhwIjoxNjU4NDE0NDAyLCJpc3MiOiJub3JpIn0.YdQo6BWChvNyqT8ptY8RwAN7bytNW38RUQOLASlpO0o',
refreshToken:
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MzAsImlhdCI6MTY1ODM4NDEwMCwiZXhwIjoxNjU5NTkzNzAwLCJpc3MiOiJub3JpIn0.AeuhSmM1ZqItojeM3O0SwrELog-Qfq91r_ii0EMgPig',
};
Expand Down
4 changes: 2 additions & 2 deletions pages/community/[cid].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export default function CommunityDetail({
'삭제하시겠어요? 삭제 시, 해당 글과 댓글은 복구되지 않습니다.',
);

if (val) {
if (val && cid) {
const status = await deleteCommunity(cid);
if (status === 200) router.push('/community');
}
Expand Down Expand Up @@ -140,7 +140,7 @@ export const getServerSideProps: GetServerSideProps<Props, Params> = async ({
const res = await getCommunityDetail(params!.cid);
return {
props: {
data: res.data.data,
data: { ...res.data.data, id: params!.cid },
},
};
};
Expand Down
17 changes: 2 additions & 15 deletions 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,25 +26,12 @@ export interface PostCommunityBody {
content: string;
imageList?: FormData;
}
// 커뮤니티 수정 put body
export interface PutCommunityBody {
category?: string;
title?: string;
content?: string;
imageList?: FormData;
}
// 커뮤니티 변경된 state 판단
export interface IsChangeCommunity {
isChangeCategory: boolean;
isChangeTitle: boolean;
isChangeContent: boolean;
isChangeImageList: boolean;
}
// 커뮤니티 댓글
export interface PostCommentBody {
boardId?: string;
content: string;
}

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

0 comments on commit 35321c1

Please sign in to comment.