From 86a6e5b27b18f663f31b3c4f736444b8954885d1 Mon Sep 17 00:00:00 2001 From: kimdaae328 Date: Fri, 28 Feb 2025 14:12:33 +0900 Subject: [PATCH] =?UTF-8?q?=EC=88=98=EC=A0=95=EB=B2=84=ED=8A=BC=20?= =?UTF-8?q?=EB=88=84=EB=A5=B4=EB=A9=B4=20=EC=B4=88=EA=B8=B0=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/board/BoardView.vue | 40 ++++++++++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/src/views/board/BoardView.vue b/src/views/board/BoardView.vue index 08411aa..eaa6dd5 100644 --- a/src/views/board/BoardView.vue +++ b/src/views/board/BoardView.vue @@ -473,16 +473,44 @@ const editComment = (comment) => { const isAnonymous = comment.author === "익명"; if (isMyComment) { - targetComment.isEditTextarea = !targetComment.isEditTextarea; - lastCommentClickedButton.value = "edit"; + if (targetComment.isEditTextarea) { + // 수정창이 열려 있는 상태에서 다시 수정 버튼을 누르면 초기화 + targetComment.isEditTextarea = false; + currentPasswordCommentId.value = comment.commentId; + } else { + // 다른 모든 댓글의 수정창 닫기 + closeAllEditTextareas(); + + // 현재 댓글만 수정 모드 활성화 + targetComment.isEditTextarea = true; + } } else if (isAnonymous) { - if (targetComment.isEditTextarea) return; - toggleCommentPassword(comment, "edit"); + if (currentPasswordCommentId.value === comment.commentId) { + // 이미 비밀번호 입력 중이면 유지 + return; + } else { + // 다른 모든 댓글의 수정창 닫기 + closeAllEditTextareas(); + + // 비밀번호 입력 + targetComment.isEditTextarea = false; + toggleCommentPassword(comment, "edit"); + } } else { alert("수정이 불가능합니다"); } } +// 모든 댓글의 수정 창 닫기 +const closeAllEditTextareas = () => { + comments.value.forEach(comment => { + comment.isEditTextarea = false; + comment.children.forEach(reply => { + reply.isEditTextarea = false; + }); + }); +}; + // 댓글 삭제 버튼 클릭 const deleteComment = async (comment) => { const isMyComment = comment.authorId === currentUserId.value; @@ -587,7 +615,9 @@ const submitCommentPassword = async (comment, password) => { if (lastCommentClickedButton.value === "edit") { if (targetComment) { - //여기서 input 창 닫혀야함 + // 다른 모든 댓글의 수정 창 닫기 + closeAllEditTextareas(); + targetComment.isEditTextarea = true; passwordCommentAlert.value = ""; currentPasswordCommentId.value = null;