댓글 좋아요

This commit is contained in:
kimdaae328 2025-02-20 15:12:12 +09:00
parent 2226782662
commit f7617e11a6
5 changed files with 96 additions and 68 deletions

View File

@ -52,17 +52,6 @@
/> />
</li> </li>
</ul> </ul>
<!-- <ul class="list-unstyled twoDepth">
<li>
<BoardProfile profileName=곤데리2 :showDetail="false" />
<div class="mt-2">저도 궁금합니다.</div>
<BoardCommentArea v-if="comment" />
</li>
</ul> -->
<!-- <BoardProfile profileName=곤데리 :showDetail="false" />
<div class="mt-2">저도 궁금합니다.</div>
<PlusButton @click="toggleComment"/>
<BoardCommentArea v-if="comment" /> -->
</div> </div>
</template> </template>
@ -73,30 +62,30 @@ import BoardCommentArea from './BoardCommentArea.vue';
import PlusButton from '../button/PlusBtn.vue'; import PlusButton from '../button/PlusBtn.vue';
const props = defineProps({ const props = defineProps({
comment: { comment: {
type: Object, type: Object,
required: true, required: true,
}, },
unknown: { unknown: {
type: Boolean,
default: true,
},
isPlusButton: {
type: Boolean, type: Boolean,
default: true, default: true,
}, },
isPlusButton: { isLike: {
type: Boolean, type: Boolean,
default: true, default: false,
}, },
isLike: { isEditTextarea: {
type: Boolean, type: Boolean,
default: false, default: false
}, },
isEditTextarea: { isPassword: {
type: Boolean, type: Boolean,
default: false default: false,
}, },
isPassword: {
type: Boolean,
default: false,
},
}); });
// emits // emits
@ -117,11 +106,28 @@ const submitComment = (newComment) => {
// , // ,
const handleUpdateReaction = (reactionData) => { const handleUpdateReaction = (reactionData) => {
// console.log('📌 BoardComment.vue :', reactionData);
// if (!reactionData.commentId) {
// console.log(" reactionData.commentId ! null .");
// }
// console.log('🟢 BoardComment.vue props.comment:', props.comment);
// console.log('🟢 BoardComment.vue commentId:', props.comment.commentId);
// console.log('🔍 emit reactionData:', {
// boardId: props.comment.boardId,
// commentId: props.comment.commentId,
// ...reactionData
// });
emit('updateReaction', { emit('updateReaction', {
boardId: props.comment.boardId, boardId: props.comment.boardId,
commentId: props.comment.commentId, commentId: props.comment.commentId || reactionData.commentId, // reactionData commentId props.comment.commentId
...reactionData ...reactionData,
}); });
// console.log('🚀 emit !');
}; };
// //

View File

@ -13,9 +13,8 @@
@deleteClick="deleteClick" @deleteClick="deleteClick"
@submitPassword="submitPassword" @submitPassword="submitPassword"
@submitComment="submitComment" @submitComment="submitComment"
@updateReaction="(reactionData) => handleUpdateReaction(reactionData, comment.commentId)" @updateReaction="(reactionData) => handleUpdateReaction(reactionData, comment.commentId, comment.boardId)"
/> />
<!-- @updateReaction="handleUpdateReaction" -->
</li> </li>
</ul> </ul>
</template> </template>
@ -46,17 +45,13 @@ const submitComment = (replyData) => {
emit('submitComment', replyData); emit('submitComment', replyData);
}; };
const handleUpdateReaction = (reactionData, commentId) => { const handleUpdateReaction = (reactionData, commentId, boardId) => {
// console.log('📢 BoardCommentList :', reactionData);
// console.log('📌 ID>>>>:', commentId);
const updatedReactionData = { const updatedReactionData = {
...reactionData, ...reactionData,
commentId: commentId commentId: commentId || reactionData.commentId,
boardId: boardId || reactionData.boardId,
}; };
// console.log('🚀 :', updatedReactionData);
emit('updateReaction', updatedReactionData); emit('updateReaction', updatedReactionData);
} }

View File

@ -31,9 +31,10 @@
<BoardRecommendBtn <BoardRecommendBtn
v-if="isLike" v-if="isLike"
:boardId="boardId" :boardId="boardId"
:comment="props.comment" :comment="comment"
@updateReaction="handleUpdateReaction" @updateReaction="handleUpdateReaction"
/> >
</BoardRecommendBtn>
</div> </div>
</div> </div>
</template> </template>

View File

@ -8,7 +8,7 @@
</template> </template>
<script setup> <script setup>
import { ref, watch } from 'vue'; import { ref, computed } from 'vue';
const props = defineProps({ const props = defineProps({
comment: { comment: {
@ -53,22 +53,13 @@ const emit = defineEmits(['updateReaction']);
const likeClicked = ref(props.likeClicked); const likeClicked = ref(props.likeClicked);
const dislikeClicked = ref(props.dislikeClicked); const dislikeClicked = ref(props.dislikeClicked);
const likeCount = ref(props.likeCount); const likeCount = computed(() => props.comment?.likeCount ?? props.likeCount);
const dislikeCount = ref(props.dislikeCount); const dislikeCount = computed(() => props.comment?.dislikeCount ?? props.dislikeCount);
// likeCount dislikeCount
watch(() => props.likeCount, (newVal) => {
likeCount.value = newVal;
});
watch(() => props.dislikeCount, (newVal) => {
dislikeCount.value = newVal;
});
const handleLike = () => { const handleLike = () => {
const isLike = !likeClicked.value; const isLike = !likeClicked.value;
const isDislike = false; const isDislike = false;
// 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;
@ -77,6 +68,7 @@ const handleLike = () => {
const handleDislike = () => { const handleDislike = () => {
const isDislike = !dislikeClicked.value; const isDislike = !dislikeClicked.value;
const isLike = false; const isLike = false;
emit('updateReaction', { boardId: props.boardId, commentId: props.commentId, isLike, isDislike }); emit('updateReaction', { boardId: props.boardId, commentId: props.commentId, isLike, isDislike });
dislikeClicked.value = isDislike; dislikeClicked.value = isDislike;
likeClicked.value = false; likeClicked.value = false;

View File

@ -101,7 +101,7 @@
:isEditTextarea="isEditTextarea" :isEditTextarea="isEditTextarea"
@editClick="editClick" @editClick="editClick"
@deleteClick="deleteClick" @deleteClick="deleteClick"
@updateReaction="handleUpdateReaction" @updateReaction="handleCommentReaction"
@submitComment="handleCommentReply" @submitComment="handleCommentReply"
/> />
<Pagination <Pagination
@ -206,15 +206,13 @@ const fetchBoardDetails = async () => {
// , // ,
const handleUpdateReaction = async ({ boardId, commentId, isLike, isDislike }) => { const handleUpdateReaction = async ({ boardId, commentId, isLike, isDislike }) => {
try { try {
const aa = await axios.post(`/board/${boardId}/${commentId}/reaction`, { await axios.post(`/board/${boardId}/${commentId}/reaction`, {
LOCBRDSEQ: boardId, // id LOCBRDSEQ: boardId, // id
LOCCMTSEQ: commentId, // id 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);
const response = await axios.get(`board/${boardId}`); const response = await axios.get(`board/${boardId}`);
const updatedData = response.data.data; const updatedData = response.data.data;
@ -226,11 +224,36 @@ const handleUpdateReaction = async ({ boardId, commentId, isLike, isDislike }) =
dislikeClicked.value = isDislike; dislikeClicked.value = isDislike;
// console.log(updatedData) // console.log(updatedData)
// console.log(" :", updatedData);
} catch (error) { } catch (error) {
alert('반응을 업데이트하는 중 오류 발생'); alert('반응을 업데이트하는 중 오류 발생');
} }
}; };
//
const handleCommentReaction = async ({ boardId, commentId, isLike, isDislike }) => {
if (!commentId) return; // ID
try {
const response = await axios.post(`/board/${boardId}/${commentId}/reaction`, {
LOCBRDSEQ: boardId, // ID
LOCCMTSEQ: commentId, // ID
LOCGOBGOD: isLike ? 'T' : 'F',
LOCGOBBAD: isDislike ? 'T' : 'F'
});
console.log("댓글 좋아요 API 응답 데이터:", response.data);
// /
await fetchComments();
} catch (error) {
alert('댓글 반응을 업데이트하는 중 오류 발생');
}
};
// //
const fetchComments = async (page = 1) => { const fetchComments = async (page = 1) => {
try { try {
@ -240,12 +263,14 @@ const fetchComments = async (page = 1) => {
page page
} }
}); });
const replyResponse = await axios.get(`board/${currentBoardId.value}/reply`, {
params: { LOCBRDSEQ: currentBoardId.value }
});
console.log("댓글:", response.data);
console.log("대댓글:", replyResponse.data); // const replyResponse = await axios.get(`board/${currentBoardId.value}/reply`, {
// params: { LOCBRDSEQ: currentBoardId.value }
// });
// console.log(":", response.data);
// console.log(":", replyResponse.data);
comments.value = response.data.data.list.map(comment => ({ comments.value = response.data.data.list.map(comment => ({
commentId: comment.LOCCMTSEQ, // ID commentId: comment.LOCCMTSEQ, // ID
@ -253,11 +278,17 @@ const fetchComments = async (page = 1) => {
parentId: comment.LOCCMTPNT, // ID parentId: comment.LOCCMTPNT, // ID
author: comment.author || "익명 사용자", author: comment.author || "익명 사용자",
content: comment.LOCCMTRPY, content: comment.LOCCMTRPY,
likeCount: comment.likeCount || 0,
dislikeCount: comment.dislikeCount || 0,
likeClicked: comment.likeClicked || false,
dislikeClicked: comment.dislikeClicked || false,
createdAtRaw: new Date(comment.LOCCMTRDT), // createdAtRaw: new Date(comment.LOCCMTRDT), //
createdAt: formattedDate(comment.LOCCMTRDT), // createdAt: formattedDate(comment.LOCCMTRDT), //
children: [] // children: [] //
})); }));
// console.log(" comments.value:", comments.value);
pagination.value = { pagination.value = {
...pagination.value, ...pagination.value,
currentPage: response.data.data.pageNum, // currentPage: response.data.data.pageNum, //
@ -274,6 +305,7 @@ const fetchComments = async (page = 1) => {
navigateLastPage: response.data.data.navigateLastPage // navigateLastPage: response.data.data.navigateLastPage //
}; };
} catch (error) { } catch (error) {
console.log('댓글 목록 불러오기 오류:', error); console.log('댓글 목록 불러오기 오류:', error);
} }
@ -288,7 +320,7 @@ const handleCommentSubmit = async ({ comment, password }) => {
LOCCMTPWD: password || null, LOCCMTPWD: password || null,
LOCCMTPNT: 1 LOCCMTPNT: 1
}); });
// console.log('📥 :', response.data); // console.log(' :', response.data);
if (response.status === 200) { if (response.status === 200) {
console.log('댓글 작성 성공:', response.data.message); console.log('댓글 작성 성공:', response.data.message);
@ -301,6 +333,8 @@ const handleCommentSubmit = async ({ comment, password }) => {
} }
}; };
//
const handleCommentReply = async (reply) => { const handleCommentReply = async (reply) => {
const response = await axios.post(`board/${currentBoardId.value}/comment`, { const response = await axios.post(`board/${currentBoardId.value}/comment`, {
LOCBRDSEQ: currentBoardId.value, LOCBRDSEQ: currentBoardId.value,