Skip to content

Commit

Permalink
[feat] #68, #56 댓글, 대댓글 기능 구현 중
Browse files Browse the repository at this point in the history
  • Loading branch information
kr-nius committed Nov 28, 2023
1 parent fad4243 commit 8c9cce9
Show file tree
Hide file tree
Showing 8 changed files with 488 additions and 62 deletions.
87 changes: 45 additions & 42 deletions src/app/detail/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import axios from "axios";
import ContentDetail from "@/component/ContentDetail";

import { RecoilRoot } from "recoil";
import CommentIcon from "@/component/CommentIcon";

export default function Detail(): JSX.Element {
const [boardDetail, setBoardDetail] = useState<any>(null);
Expand All @@ -21,8 +22,10 @@ export default function Detail(): JSX.Element {
const fetchData = async () => {
try {
const response = await axios.get(
"https://www.jerneithe.site/board/detail/{boardId}",
// "https://www.jerneithe.site/board/detail/3",
// 메인용
`https://www.jerneithe.site/board/detail/${boardDetail.boardId}`
// 테스트용
// "https://www.jerneithe.site/board/detail/1"
);
setBoardDetail(response.data);
} catch (error) {
Expand All @@ -35,48 +38,48 @@ export default function Detail(): JSX.Element {

return (
// <RecoilRoot>
<div className="container">
<header className="top w-full">
<div className="w-full h-12 flex items-center ">
<Image
src="/images/back.svg"
width={15}
height={15}
className="ml-3 cursor-pointer"
alt="back"
onClick={() => {
window.history.back();
}}
/>
</div>
<hr className="w-full h-px" />
<WeatherBar />
<hr className="w-full h-px" />
</header>
<div className="container">
<header className="top w-full">
<div className="w-full h-12 flex items-center ">
<Image
src="/images/back.svg"
width={15}
height={15}
className="ml-3 cursor-pointer"
alt="back"
onClick={() => {
window.history.back();
}}
/>
</div>
<hr className="w-full h-px" />
<WeatherBar />
<hr className="w-full h-px" />
</header>

<section className="main w-5/6 h-full">
{boardDetail && (
<>
<Profile nickName={boardDetail.nickName} />
<div className="contents w-full">
<ImageDetail images={boardDetail.images} />
<ContentDetail
content={boardDetail.content}
hashTag={boardDetail.hashTag}
/>
</div>
<div className="button flex">
<Like />
<Comments />
</div>
</>
)}
</section>
<section className="main w-5/6 h-full">
{boardDetail && (
<>
<Profile nickName={boardDetail.nickName} />
<div className="contents w-full">
<ImageDetail images={boardDetail.images} />
<ContentDetail
content={boardDetail.content}
hashTag={boardDetail.hashTag}
/>
</div>
<div className="button flex">
<Like />
<CommentIcon />
</div>
</>
)}
</section>

<footer className="w-full">
<Menubar />
</footer>
</div>
<footer className="w-full">
<Menubar />
</footer>
</div>
// </RecoilRoot>
);
}
68 changes: 68 additions & 0 deletions src/component/Comment.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
interface ReplyType {
text: string;
createdAt: Date;
}

interface CommentType {
nickname: string;
comment: string;
reply: ReplyType[];
showReplyInput: boolean;
isDeleted: boolean;
createdAt: Date;
}

interface CommentProps {
item: CommentType;
index: number;
handleEdit: (
index: number,
type: "comment" | "reply",
replyIndex?: number
) => void;
handleDelete: (index: number) => void;
getTimeDiff: (date: Date) => string;
editing?: {
index: number;
type: "comment" | "reply";
replyIndex?: number;
};
handleEditSubmit: (e: React.FormEvent) => void;
editText: string;
handleEditChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
}

export default function Comment({
item,
index,
handleEdit,
handleDelete,
getTimeDiff,
editing,
handleEditSubmit,
editText,
handleEditChange,
}: CommentProps) {
return (
<div key={index}>
{editing?.index === index && editing.type === "comment" ? (
<form onSubmit={handleEditSubmit}>
<p key={`comment-${index}`}>{item.nickname}:</p>
<input type="text" value={editText} onChange={handleEditChange} />
<button type="submit">완료</button>
</form>
) : (
<p key={`comment-${index}`}>
{item.nickname}: {item.isDeleted ? item.comment : item.comment} (
{getTimeDiff(item.createdAt)})
{!item.isDeleted && (
<>
<button onClick={() => handleEdit(index, "comment")}>수정</button>
<button onClick={() => handleDelete(index)}>삭제</button>
</>
)}
</p>
)}
</div>
);
}
30 changes: 30 additions & 0 deletions src/component/CommentIcon.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"use client";
import React, { useState } from "react";
import Image from "next/image";
import CommentModal from "@/component/CommentModal";

export default function CommentIcon() {
// 댓글 모달
const [showCommentsModal, setShowCommentsModal] = useState<boolean>(false);

// 회원 정보 수정 모달 이벤트
const handleCommentClick = () => {
setShowCommentsModal(!showCommentsModal);
};

return (
<>
<Image
src="/images/comment.svg"
alt="comment"
width={20}
height={20}
className="cursor-pointer"
onClick={handleCommentClick}
/>
{showCommentsModal && (
<CommentModal handleModalToggle={handleCommentClick} />
)}
</>
);
}
Loading

0 comments on commit 8c9cce9

Please sign in to comment.