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;