댓글 좋아요 완료

This commit is contained in:
kimdaae328 2025-02-17 13:56:02 +09:00
parent 499162639a
commit 5fe85dcd3b
5 changed files with 74 additions and 47 deletions

View File

@ -4,6 +4,7 @@
:boardId="comment.boardId" :boardId="comment.boardId"
:profileName="comment.author" :profileName="comment.author"
:date="comment.createdAt" :date="comment.createdAt"
:comment="comment"
:showDetail="false" :showDetail="false"
:author="true" :author="true"
:isLike="!isLike" :isLike="!isLike"
@ -85,8 +86,14 @@ const submitComment = (newComment) => {
// , // ,
const handleUpdateReaction = (reactionData) => { const handleUpdateReaction = (reactionData) => {
console.log(`🛠 좋아요/싫어요 클릭됨:`, reactionData); // console.log('📌 comment:', props.comment.commentId);
// emit('updateReaction', { boardId: props.comment.boardId, commentId: props.comment.id, ...reactionData });
emit('updateReaction', {
boardId: props.comment.boardId,
commentId: props.comment.commentId,
...reactionData
});
}; };

View File

@ -8,8 +8,9 @@
<BoardComment <BoardComment
:comment="comment" :comment="comment"
@submitComment="submitComment" @submitComment="submitComment"
@updateReaction="handleUpdateReaction" @updateReaction="(reactionData) => handleUpdateReaction(reactionData, comment.commentId)"
/> />
<!-- @updateReaction="handleUpdateReaction" -->
</li> </li>
</ul> </ul>
</template> </template>
@ -23,7 +24,7 @@ const props = defineProps({
type: Array, type: Array,
required: true, required: true,
default: () => [] default: () => []
} },
}); });
const emit = defineEmits(['submitComment', 'updateReaction']); const emit = defineEmits(['submitComment', 'updateReaction']);
@ -32,9 +33,22 @@ const submitComment = (replyData) => {
emit('submitComment', replyData); emit('submitComment', replyData);
}; };
const handleUpdateReaction = (reactionData) => { const handleUpdateReaction = (reactionData, commentId) => {
console.log(`📢 부모 컴포넌트에서 이벤트 수신:`, reactionData); // console.log('📢 BoardCommentList :', reactionData);
// emit('updateReaction', { boardId: props.comment.boardId, commentId: props.comment.id, ...reactionData }); // console.log('📌 ID>>>>:', commentId);
};
// if (commentId) {
// console.error("");
// }
const updatedReactionData = {
...reactionData,
commentId: commentId
};
// console.log('🚀 :', updatedReactionData);
emit('updateReaction', updatedReactionData);
}
</script> </script>

View File

@ -42,7 +42,12 @@
</div> </div>
<!-- 좋아요, 싫어요 버튼 (댓글에서만 표시) --> <!-- 좋아요, 싫어요 버튼 (댓글에서만 표시) -->
<BoardRecommendBtn v-if="isLike" :boardId="boardId" :comment="comment" @updateReaction="handleUpdateReaction" /> <BoardRecommendBtn
v-if="isLike"
:boardId="boardId"
:comment="props.comment"
@updateReaction="handleUpdateReaction"
/>
</div> </div>
</div> </div>
</template> </template>
@ -64,6 +69,10 @@ const lastClickedButton = ref('');
// Props // Props
const props = defineProps({ const props = defineProps({
comment: {
type: Object,
required: true,
},
boardId: { boardId: {
type: Number, type: Number,
required: false required: false
@ -201,12 +210,16 @@ const deletePost = async () => {
const handleUpdateReaction = (reactionData) => { const handleUpdateReaction = (reactionData) => {
// console.log(`🔥 BoardProfile / `, reactionData); // console.log("🔥 BoardProfile / ");
console.log("🔥 좋아요/싫어요 이벤트 발생"); // console.log("📌 ID:", props.boardId);
console.log("📌 게시글 ID (props.boardId):", props.boardId); // console.log("📌 ID ( ):", props.comment?.commentId);
console.log("📌 댓글 ID (props.comment?.id):", props.comment?.commentId); // console.log("📌 reactionData:", reactionData);
console.log("📌 댓글의 게시글 ID (props.comment?.boardId):", props.comment?.boardId);
// emit('updateReaction', { boardId: props.comment.boardId, commentId: props.comment.commentId, ...reactionData }); emit("updateReaction", {
boardId: props.boardId,
commentId: props.comment?.commentId,
...reactionData,
});
}; };
</script> </script>

View File

@ -11,6 +11,10 @@
import { ref, watch } from 'vue'; import { ref, watch } from 'vue';
const props = defineProps({ const props = defineProps({
comment: {
type: Object,
required: true,
},
likeClicked : { likeClicked : {
type : Boolean, type : Boolean,
default : false, default : false,
@ -64,7 +68,7 @@ watch(() => props.dislikeCount, (newVal) => {
const handleLike = () => { const handleLike = () => {
const isLike = !likeClicked.value; const isLike = !likeClicked.value;
const isDislike = false; const isDislike = false;
// console.log("BoardRecommendBtn.vue - commentId:", props.commentId); // console.log('')
emit('updateReaction', { boardId: props.boardId, commentId: props.commentId, isLike, isDislike }); emit('updateReaction', { boardId: props.boardId, commentId: props.commentId, isLike, isDislike });
likeClicked.value = isLike; likeClicked.value = isLike;
dislikeClicked.value = false; dislikeClicked.value = false;

View File

@ -74,8 +74,7 @@
<!-- 댓글 목록 --> <!-- 댓글 목록 -->
<div class="card-footer"> <div class="card-footer">
<BoardCommentList :comments="comments" @submitComment="handleCommentReply"/> <BoardCommentList :comments="comments" @updateReaction="handleUpdateReaction" @submitComment="handleCommentReply" />
<Pagination/> <Pagination/>
</div> </div>
</div> </div>
@ -149,45 +148,35 @@ const fetchBoardDetails = async () => {
// , // ,
const handleUpdateReaction = async ({ boardId, commentId, isLike, isDislike }) => { const handleUpdateReaction = async ({ boardId, commentId, isLike, isDislike }) => {
console.log("🔥 좋아요/싫어요 이벤트 발생");
console.log("📌 게시글 ID:", boardId); console.log("📌 게시글 ID:", boardId);
console.log("📌 댓글 ID:", commentId); console.log("📌 댓글 ID (최종):", commentId);
try { try {
await axios.post(`/board/${boardId}/${commentId}/reaction`, { const aa = await axios.post(`/board/${boardId}/${commentId}/reaction`, {
LOCBRDSEQ: boardId, LOCBRDSEQ: boardId, // id
LOCCMTSEQ: commentId, LOCCMTSEQ: commentId, // id
MEMBERSEQ: 1, // 1 // MEMBERSEQ: 1, // 1
LOCGOBGOD: isLike ? 'T' : 'F', LOCGOBGOD: isLike ? 'T' : 'F',
LOCGOBBAD: isDislike ? 'T' : 'F' LOCGOBBAD: isDislike ? 'T' : 'F'
}); });
console.log("📥 API 응답 데이터:", aa.data);
console.log(commentId)
if (commentId) { const response = await axios.get(`board/${boardId}`);
console.log('댓글 좋아요/싫어요 누름 -> commentId:', commentId); const updatedData = response.data.data;
await fetchComments();
} else {
console.log('게시글 좋아요/싫어요 누름 -> boardId:', boardId);
const response = await axios.get(`board/${boardId}`); const response2 = await axios.get(`board/${boardId}/comments`);
const updatedData = response.data.data;
likes.value = updatedData.likeCount;
dislikes.value = updatedData.dislikeCount;
likeClicked.value = isLike; // console.log("📥 API :", response2);
dislikeClicked.value = isDislike;
console.log('게시글 업데이트된 데이터:', updatedData);
}
// const response = await axios.get(`board/${boardId}`);
// const updatedData = response.data.data;
// likes.value = updatedData.likeCount;
// dislikes.value = updatedData.dislikeCount;
// likeClicked.value = isLike; likes.value = updatedData.likeCount;
// dislikeClicked.value = isDislike; dislikes.value = updatedData.dislikeCount;
likeClicked.value = isLike;
dislikeClicked.value = isDislike;
// console.log(updatedData)
} catch (error) { } catch (error) {
alert('반응을 업데이트하는 중 오류 발생'); alert('반응을 업데이트하는 중 오류 발생');
@ -200,7 +189,7 @@ const fetchComments = async () => {
const response = await axios.get(`board/${currentBoardId.value}/comments`, { const response = await axios.get(`board/${currentBoardId.value}/comments`, {
params: { LOCBRDSEQ: currentBoardId.value } params: { LOCBRDSEQ: currentBoardId.value }
}); });
// console.log("📥 API :", response.data); console.log("📥 API 응답 데이터:", response.data);
let allComments = response.data.data.list.map(comment => ({ let allComments = response.data.data.list.map(comment => ({
commentId: comment.LOCCMTSEQ, // id commentId: comment.LOCCMTSEQ, // id
@ -231,7 +220,7 @@ const fetchComments = async () => {
comments.value = rootComments; comments.value = rootComments;
console.log("변환된 comments 데이터:", comments.value); // console.log(" comments :", comments.value);
} catch (error) { } catch (error) {
console.error('댓글 목록 불러오기 오류:', error); console.error('댓글 목록 불러오기 오류:', error);