대댓글 수정중

This commit is contained in:
kimdaae328 2025-02-19 23:38:40 +09:00
parent 6d705d1093
commit bba4c60cb2
2 changed files with 51 additions and 28 deletions

View File

@ -23,11 +23,12 @@
<textarea v-model="editedContent" class="form-control"></textarea> <textarea v-model="editedContent" class="form-control"></textarea>
<div class="mt-2 d-flex justify-content-end"> <div class="mt-2 d-flex justify-content-end">
<button class="btn btn-secondary me-2" @click="emit('toggleEdit', comment.commentId, false)">취소</button> <button class="btn btn-secondary me-2" @click="emit('toggleEdit', comment.commentId, false)">취소</button>
<button class="btn btn-primary" @click="submitEdit">수정 완료</button> <button class="btn btn-primary" @click="submitEdit">수정</button>
</div> </div>
</template> </template>
<template v-else> <template v-else>
<p class="m-0">{{ comment.content }}</p> <p class="m-0">{{ comment.content }}</p>
<span>{{ comment.commentId }}</span>
</template> </template>
</div> </div>

View File

@ -223,42 +223,64 @@ const handleUpdateReaction = async ({ boardId, commentId, isLike, isDislike }) =
// //
const fetchComments = async (page = 1) => { const fetchComments = async (page = 1) => {
try { try {
const response = await axios.get(`board/${currentBoardId.value}/comments`, { const { data } = await axios.get(`board/${currentBoardId.value}/comments`, {
params: { params: { LOCBRDSEQ: currentBoardId.value, page }
LOCBRDSEQ: currentBoardId.value,
page
}
}); });
console.log("목록 API 응답 데이터:", response.data); const { data: replyData } = await axios.get(`board/${currentBoardId.value}/reply`, {
params: { LOCBRDSEQ: currentBoardId.value }
});
console.log("댓글:", data);
console.log("대댓글:", replyData);
let allComments = response.data.data.list.map(comment => ({ if (!data?.data?.list) return;
commentId: comment.LOCCMTSEQ, // id
comments.value = data.data.list.map(comment => ({
commentId: comment.LOCCMTSEQ, // ID
boardId: comment.LOCBRDSEQ, boardId: comment.LOCBRDSEQ,
parentId: comment.LOCCMTPNT, // id parentId: comment.LOCCMTPNT, // ID
author: comment.author || "익명 사용자", // author: comment.author || "익명 사용자",
content: comment.LOCCMTRPY, // content: comment.LOCCMTRPY,
createdAt: formattedDate(comment.LOCCMTRDT), // createdAtRaw: new Date(comment.LOCCMTRDT), //
children: [] createdAt: formattedDate(comment.LOCCMTRDT), //
children: [] //
})); }));
allComments.sort((a, b) => b.commentId - a.commentId); let replies = replyData.data.map(reply => ({
commentId: reply.LOCCMTSEQ, // ID
boardId: reply.LOCBRDSEQ,
parentId: reply.LOCCMTPNT, // ID
author: reply.author || "익명 사용자",
content: reply.LOCCMTRPY,
createdAtRaw: new Date(reply.LOCCMTRDT), //
createdAt: formattedDate(reply.LOCCMTRDT) //
}));
let commentMap = {}; // let commentMap = {};
let rootComments = []; // let rootComments = [];
allComments.forEach(comment => { //
commentMap[comment.commentId] = comment; // allComments.forEach(comment => {
}); // commentMap[comment.commentId] = comment;
// });
allComments.forEach(comment => { //
if (comment.parentId && commentMap[comment.parentId]) { // replies.forEach(reply => {
commentMap[comment.parentId].children.push(comment); // if (commentMap[reply.parentId]) {
} else { // commentMap[reply.parentId].children.push(reply);
rootComments.push(comment); // } else {
} // console.warn(" :", reply);
}); // }
// });
comments.value = rootComments; // rootComments = allComments.filter(comment => comment.parentId === 1);
//
// rootComments.sort((a, b) => b.createdAtRaw - a.createdAtRaw);
// rootComments.forEach(comment => {
// comment.children.sort((a, b) => b.createdAtRaw - a.createdAtRaw);
// });
// comments.value = rootComments;
// console.log(" comments :", comments.value); // console.log(" comments :", comments.value);