This commit is contained in:
kimdaae328 2025-02-17 09:45:27 +09:00
parent a1efaf1d90
commit 2b7dabf27e
5 changed files with 91 additions and 51 deletions

View File

@ -1,23 +1,26 @@
<template>
<div>
<BoardProfile
:boardId="comment.boardId"
:profileName="comment.author"
:date="comment.createdAt"
:showDetail="false"
:author="true"
:isLike="!isLike"
@updateReaction="handleUpdateReaction"
/>
<div class="mt-6">
<p class="m-0">{{ comment.content }}</p>
<!-- <span>{{comment.commentId}}</span> -->
</div>
<PlusButton v-if="isPlusButton" @click="toggleComment" class="mt-6"/>
<BoardComentArea v-if="isComment" @submitComment="submitComment"/>
<!-- 대댓글 -->
<ul v-if="comment.children && comment.children.length" class="list-unstyled">
<li
v-for="child in comment.children"
:key="child.id"
v-for="child in comment.children"
:key="child.commentId"
class="mt-8 pt-6 ps-10 border-top"
>
<BoardComment
@ -25,6 +28,7 @@
:isPlusButton="false"
:isLike="true"
@submitComment="submitComment"
@updateReaction="handleUpdateReaction"
/>
</li>
</ul>
@ -64,7 +68,7 @@ const props = defineProps({
});
// emits
const emit = defineEmits(['submitComment']);
const emit = defineEmits(['submitComment', 'updateReaction']);
//
const isComment = ref(false);
@ -74,10 +78,16 @@ const toggleComment = () => {
//
const submitComment = (newComment) => {
emit('submitComment', { parentId: props.comment.id, ...newComment });
emit('submitComment', { parentId: props.comment.commentId, ...newComment });
isComment.value = false;
};
// ,
const handleUpdateReaction = (reactionData) => {
console.log(`🛠 좋아요/싫어요 클릭됨:`, reactionData);
// emit('updateReaction', { boardId: props.comment.boardId, commentId: props.comment.id, ...reactionData });
};
</script>

View File

@ -2,12 +2,13 @@
<ul class="list-unstyled mt-10">
<li
v-for="comment in comments"
:key="comment.id"
:key="comment.commentId"
class="mt-6 border-bottom pb-6"
>
<BoardComment
:comment="comment"
@submitComment="submitComment"
@updateReaction="handleUpdateReaction"
/>
</li>
</ul>
@ -25,10 +26,15 @@ const props = defineProps({
}
});
const emit = defineEmits(['submitComment']);
const emit = defineEmits(['submitComment', 'updateReaction']);
const submitComment = (replyData) => {
emit('submitComment', replyData);
};
const handleUpdateReaction = (reactionData) => {
console.log(`📢 부모 컴포넌트에서 이벤트 수신:`, reactionData);
// emit('updateReaction', { boardId: props.comment.boardId, commentId: props.comment.id, ...reactionData });
};
</script>

View File

@ -42,13 +42,13 @@
</div>
<!-- 좋아요, 싫어요 버튼 (댓글에서만 표시) -->
<BoardRecommendBtn v-if="isLike" :isRecommend="false" />
<BoardRecommendBtn v-if="isLike" :boardId="boardId" :comment="comment" @updateReaction="handleUpdateReaction" />
</div>
</div>
</template>
<script setup>
import { ref, defineProps, computed } from 'vue';
import { ref, defineProps, defineEmits } from 'vue';
import { useRouter } from 'vue-router';
import axios from '@api';
import DeleteButton from '../button/DeleteBtn.vue';
@ -66,7 +66,11 @@ const lastClickedButton = ref('');
const props = defineProps({
boardId: {
type: Number,
required: true
required: false
},
commentId: {
type: Number,
required: false,
},
profileName: {
type: String,
@ -103,7 +107,7 @@ const props = defineProps({
}
});
const emit = defineEmits(['togglePasswordInput']);
const emit = defineEmits(['togglePasswordInput', 'updateReaction']);
//
const handleEdit = () => {
@ -195,6 +199,16 @@ const deletePost = async () => {
}
};
const handleUpdateReaction = (reactionData) => {
// console.log(`🔥 BoardProfile / `, reactionData);
console.log("🔥 좋아요/싫어요 이벤트 발생");
console.log("📌 게시글 ID (props.boardId):", props.boardId);
console.log("📌 댓글 ID (props.comment?.id):", props.comment?.commentId);
console.log("📌 댓글의 게시글 ID (props.comment?.boardId):", props.comment?.boardId);
// emit('updateReaction', { boardId: props.comment.boardId, commentId: props.comment.commentId, ...reactionData });
};
</script>
<style scoped>

View File

@ -63,7 +63,8 @@ watch(() => props.dislikeCount, (newVal) => {
const handleLike = () => {
const isLike = !likeClicked.value;
const isDislike = false;
const isDislike = false;
// console.log("BoardRecommendBtn.vue - commentId:", props.commentId);
emit('updateReaction', { boardId: props.boardId, commentId: props.commentId, isLike, isDislike });
likeClicked.value = isLike;
dislikeClicked.value = false;

View File

@ -128,7 +128,7 @@ const fetchBoardDetails = async () => {
profileName.value = data.author || '익명 사용자';
//
// profileName.value = ' ';
profileName.value = '익명 사용자';
// :
authorId.value = data.author;
@ -149,6 +149,9 @@ const fetchBoardDetails = async () => {
// ,
const handleUpdateReaction = async ({ boardId, commentId, isLike, isDislike }) => {
console.log("🔥 좋아요/싫어요 이벤트 발생");
console.log("📌 게시글 ID:", boardId);
console.log("📌 댓글 ID:", commentId);
try {
await axios.post(`/board/${boardId}/${commentId}/reaction`, {
LOCBRDSEQ: boardId,
@ -158,16 +161,33 @@ const handleUpdateReaction = async ({ boardId, commentId, isLike, isDislike }) =
LOCGOBBAD: isDislike ? 'T' : 'F'
});
console.log(commentId)
if (commentId) {
console.log('댓글 좋아요/싫어요 누름 -> commentId:', commentId);
await fetchComments();
} else {
console.log('게시글 좋아요/싫어요 누름 -> boardId:', boardId);
const response = await axios.get(`board/${boardId}`);
const updatedData = response.data.data;
likes.value = updatedData.likeCount;
dislikes.value = updatedData.dislikeCount;
likeClicked.value = isLike;
dislikeClicked.value = isDislike;
console.log('게시글 업데이트된 데이터:', updatedData);
}
const response = await axios.get(`board/${boardId}`);
console.log(response.data)
const updatedData = response.data.data;
// const response = await axios.get(`board/${boardId}`);
// const updatedData = response.data.data;
likes.value = updatedData.likeCount;
dislikes.value = updatedData.dislikeCount;
// likes.value = updatedData.likeCount;
// dislikes.value = updatedData.dislikeCount;
likeClicked.value = isLike;
dislikeClicked.value = isDislike;
// likeClicked.value = isLike;
// dislikeClicked.value = isDislike;
} catch (error) {
alert('반응을 업데이트하는 중 오류 발생');
@ -180,12 +200,14 @@ const fetchComments = async () => {
const response = await axios.get(`board/${currentBoardId.value}/comments`, {
params: { LOCBRDSEQ: currentBoardId.value }
});
console.log("📥 API 응답 데이터:", response.data);
// console.log("📥 API :", response.data);
let allComments = response.data.data.map(comment => ({
id: comment.LOCCMTSEQ, // id
let allComments = response.data.data.list.map(comment => ({
// id
boardId: comment.LOCBRDSEQ,
parentId: comment.LOCCMTPNT, // id
author: comment.MEMBERSEQ || "익명 사용자", //
author: comment.author || "익명 사용자", //
content: comment.LOCCMTRPY, //
createdAt: formattedDate(comment.LOCCMTRDT), //
children: []
@ -197,7 +219,7 @@ const fetchComments = async () => {
let rootComments = [];
allComments.forEach(comment => {
commentMap[comment.id] = comment;
commentMap[comment.boardId] = comment;
});
allComments.forEach(comment => {
@ -210,7 +232,7 @@ const fetchComments = async () => {
comments.value = rootComments;
// console.log(" comments :", comments.value);
console.log("변환된 comments 데이터:", comments.value);
} catch (error) {
console.error('댓글 목록 불러오기 오류:', error);
@ -227,7 +249,6 @@ const handleCommentSubmit = async ({ comment, password }) => {
LOCCMTPNT: 1
});
// console.log('📥 :', response.data);
if (response.status === 200) {
console.log('댓글 작성 성공:', response.data.message);
@ -241,31 +262,19 @@ const handleCommentSubmit = async ({ comment, password }) => {
};
const handleCommentReply = async (reply) => {
// console.log("BoardView ~~~~~~~~~~~~~~~~:", reply);
const response = await axios.post(`board/${currentBoardId.value}/comment`, {
LOCBRDSEQ: currentBoardId.value,
LOCCMTRPY: reply.comment,
LOCCMTPWD: reply.password || null,
LOCCMTPNT: reply.parentId
});
//
// const parentComment = comments.value.find(comment => comment.id === reply.parentId);
// console.log(parentComment)
// if (parentComment) {
// console.log('??')
const response = await axios.post(`board/${currentBoardId.value}/comment`, {
LOCBRDSEQ: currentBoardId.value,
LOCCMTRPY: reply.comment,
LOCCMTPWD: reply.password || null,
LOCCMTPNT: reply.parentId
});
if (response.status === 200) {
console.log('대댓글 작성 성공!!!!!!:', response.data.message);
await fetchComments();
} else {
console.error('대댓글 작성 실패ㅜㅜㅜ:', response.data.message);
}
// } else {
// console.error(` : ${reply.parentId}`);
// }
if (response.status === 200) {
console.log('대댓글 작성 성공!!!!!!:', response.data.message);
await fetchComments();
} else {
console.error('대댓글 작성 실패ㅜㅜㅜ:', response.data.message);
}
}
//