대댓글 수정중

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>
<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-primary" @click="submitEdit">수정 완료</button>
<button class="btn btn-primary" @click="submitEdit">수정</button>
</div>
</template>
<template v-else>
<p class="m-0">{{ comment.content }}</p>
<span>{{ comment.commentId }}</span>
</template>
</div>

View File

@ -223,42 +223,64 @@ const handleUpdateReaction = async ({ boardId, commentId, isLike, isDislike }) =
//
const fetchComments = async (page = 1) => {
try {
const response = await axios.get(`board/${currentBoardId.value}/comments`, {
params: {
LOCBRDSEQ: currentBoardId.value,
page
}
const { data } = await axios.get(`board/${currentBoardId.value}/comments`, {
params: { 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 => ({
commentId: comment.LOCCMTSEQ, // id
if (!data?.data?.list) return;
comments.value = data.data.list.map(comment => ({
commentId: comment.LOCCMTSEQ, // ID
boardId: comment.LOCBRDSEQ,
parentId: comment.LOCCMTPNT, // id
author: comment.author || "익명 사용자", //
content: comment.LOCCMTRPY, //
createdAt: formattedDate(comment.LOCCMTRDT), //
children: []
parentId: comment.LOCCMTPNT, // ID
author: comment.author || "익명 사용자",
content: comment.LOCCMTRPY,
createdAtRaw: new Date(comment.LOCCMTRDT), //
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 rootComments = [];
// let commentMap = {};
// 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]) {
commentMap[comment.parentId].children.push(comment);
} else {
rootComments.push(comment);
}
});
//
// replies.forEach(reply => {
// if (commentMap[reply.parentId]) {
// commentMap[reply.parentId].children.push(reply);
// } 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);