boardview 에서 수정, 삭제시 버튼 클릭 활성화

This commit is contained in:
nevermoregb 2025-04-03 22:17:30 +09:00
parent 2072a41ca9
commit 7e0ae7063d
6 changed files with 172 additions and 52 deletions

View File

@ -12,6 +12,8 @@
:isLike="!isLike" :isLike="!isLike"
:isCommentPassword="isCommentPassword" :isCommentPassword="isCommentPassword"
:isCommentProfile="true" :isCommentProfile="true"
:is-edit-pushed="isEditPushed"
:is-delete-pushed="isDeletePushed"
@editClick="handleEditClick" @editClick="handleEditClick"
@deleteClick="$emit('deleteClick', comment)" @deleteClick="$emit('deleteClick', comment)"
@updateReaction="handleUpdateReaction" @updateReaction="handleUpdateReaction"
@ -116,9 +118,20 @@
password: { password: {
type: String, type: String,
}, },
// isEditPushed: {
// type: Boolean,
// required: false,
// },
// isDeletePushed: {
// type: Boolean,
// required: false,
// },
editCommentAlert: String, editCommentAlert: String,
}); });
const isEditPushed = ref(false);
const isDeletePushed = ref(false);
const displayName = computed(() => { const displayName = computed(() => {
return props.nickname ? props.nickname : props.comment.author; return props.nickname ? props.nickname : props.comment.author;
}); });
@ -171,6 +184,24 @@
emit('submitPassword', props.comment, props.password); emit('submitPassword', props.comment, props.password);
}; };
const handleInject = inject('isBtnPushed');
// ,
watch(
() => handleInject.value,
(newValue, oldValue) => {
if (newValue) {
if (newValue.target == props.comment.commentId) {
isEditPushed.value = newValue.isEditPushed;
isDeletePushed.value = newValue.isDeletePushed;
} else {
isEditPushed.value = false;
isDeletePushed.value = false;
}
}
},
);
watch( watch(
() => props.comment.isEditTextarea, () => props.comment.isEditTextarea,
newVal => { newVal => {

View File

@ -13,6 +13,8 @@
:currentPasswordCommentId="currentPasswordCommentId" :currentPasswordCommentId="currentPasswordCommentId"
:password="password" :password="password"
:editCommentAlert="editCommentAlert[comment.commentId]" :editCommentAlert="editCommentAlert[comment.commentId]"
:is-edit-pushed="comment.isEditPushed"
:is-delete-pushed="comment.isDeletePushed"
@editClick="handleEditClick" @editClick="handleEditClick"
@deleteClick="handleDeleteClick" @deleteClick="handleDeleteClick"
@submitPassword="submitPassword" @submitPassword="submitPassword"
@ -40,6 +42,8 @@
:passwordCommentAlert="passwordCommentAlert" :passwordCommentAlert="passwordCommentAlert"
:password="password" :password="password"
:editCommentAlert="editCommentAlert[child.commentId]" :editCommentAlert="editCommentAlert[child.commentId]"
:is-edit-pushed="child.isEditPushed"
:is-delete-pushed="child.isDeletePushed"
@editClick="handleReplyEditClick" @editClick="handleReplyEditClick"
@deleteClick="$emit('deleteClick', child)" @deleteClick="$emit('deleteClick', child)"
@submitEdit="(comment, editedContent) => $emit('submitEdit', comment, editedContent, child.commentId)" @submitEdit="(comment, editedContent) => $emit('submitEdit', comment, editedContent, child.commentId)"
@ -59,7 +63,7 @@
</template> </template>
<script setup> <script setup>
import { defineProps, defineEmits } from 'vue'; import { defineProps, defineEmits, watch } from 'vue';
import BoardComment from './BoardComment.vue'; import BoardComment from './BoardComment.vue';
const props = defineProps({ const props = defineProps({

View File

@ -27,8 +27,8 @@
<!-- 수정, 삭제 버튼 --> <!-- 수정, 삭제 버튼 -->
<template v-if="!isDeletedComment && (unknown || isCommentAuthor || isAuthor)"> <template v-if="!isDeletedComment && (unknown || isCommentAuthor || isAuthor)">
<div class="float-end ms-1"> <div class="float-end ms-1">
<EditButton @click.stop="editClick" /> <EditButton @click.stop="editClick" :is-pushed="isEditPushed" />
<DeleteButton :class="'ms-1'" @click.stop="deleteClick" /> <DeleteButton :class="'ms-1'" @click.stop="deleteClick" :is-pushed="isDeletePushed" />
</div> </div>
</template> </template>
@ -107,6 +107,14 @@
type: String, type: String,
default: false, default: false,
}, },
isEditPushed: {
type: Boolean,
require: false,
},
isDeletePushed: {
type: Boolean,
require: false,
},
}); });
const emit = defineEmits(['updateReaction', 'editClick', 'deleteClick']); const emit = defineEmits(['updateReaction', 'editClick', 'deleteClick']);

View File

@ -1,13 +1,14 @@
<template> <template>
<button class="btn btn-label-primary btn-icon"> <button class="btn btn-label-primary btn-icon" :class="{ active: props.isPushed }">
<i class='bx bx-trash' ></i> <i class="bx bx-trash"></i>
</button> </button>
</template> </template>
<script> <script setup>
export default { const props = defineProps({
name: 'DeleteButton', isPushed: {
methods: { type: Boolean,
}, required: false,
}; },
});
</script> </script>

View File

@ -1,10 +1,10 @@
<template> <template>
<button class="btn btn-label-primary btn-icon" @click="toggleText"> <button class="btn btn-label-primary btn-icon" :class="{ active: props.isPushed }" @click="toggleText">
<i :class="buttonClass"></i> <i :class="buttonClass"></i>
</button> </button>
</template> </template>
<script setup> <script setup>
import { ref, watch, defineProps, defineEmits, watchEffect } from 'vue'; import { ref, watch, defineEmits, watchEffect } from 'vue';
const props = defineProps({ const props = defineProps({
isToggleEnabled: { isToggleEnabled: {
type: Boolean, type: Boolean,
@ -14,18 +14,22 @@
type: Boolean, type: Boolean,
required: false, required: false,
}, },
isPushed: {
type: Boolean,
required: false,
},
}); });
const emit = defineEmits(["click"]); const emit = defineEmits(['click']);
const buttonClass = ref('bx bx-edit-alt'); const buttonClass = ref('bx bx-edit-alt');
watchEffect(() => { watchEffect(() => {
buttonClass.value = props.isActive ? 'bx bx-x' : 'bx bx-edit-alt'; buttonClass.value = props.isActive ? 'bx bx-x' : 'bx bx-edit-alt';
}); });
const toggleText = (event) => { const toggleText = event => {
// //
if (props.isToggleEnabled) { if (props.isToggleEnabled) {
buttonClass.value = buttonClass.value === 'bx bx-edit-alt' ? 'bx bx-x' : 'bx bx-edit-alt'; buttonClass.value = buttonClass.value === 'bx bx-edit-alt' ? 'bx bx-x' : 'bx bx-edit-alt';
} }
emit("click", event); // emit('click', event); //
}; };
const resetButton = () => { const resetButton = () => {
buttonClass.value = 'bx bx-edit-alt'; buttonClass.value = 'bx bx-edit-alt';

View File

@ -17,6 +17,8 @@
:date="formattedBoardDate" :date="formattedBoardDate"
:isLike="false" :isLike="false"
:isAuthor="isAuthor" :isAuthor="isAuthor"
:is-edit-pushed="isEditPushed"
:is-delete-pushed="isDeletePushed"
@editClick="editClick" @editClick="editClick"
@deleteClick="deleteClick" @deleteClick="deleteClick"
/> />
@ -92,7 +94,7 @@
@updateReaction="handleUpdateReaction" @updateReaction="handleUpdateReaction"
/> />
</div> </div>
<div v-if="!type" > <div v-if="!type">
<!-- 댓글 입력 영역 --> <!-- 댓글 입력 영역 -->
<BoardCommentArea <BoardCommentArea
:profileName="profileName" :profileName="profileName"
@ -142,7 +144,7 @@
import BoardCommentList from '@c/board/BoardCommentList.vue'; import BoardCommentList from '@c/board/BoardCommentList.vue';
import BoardRecommendBtn from '@c/button/BoardRecommendBtn.vue'; import BoardRecommendBtn from '@c/button/BoardRecommendBtn.vue';
import Pagination from '@c/pagination/Pagination.vue'; import Pagination from '@c/pagination/Pagination.vue';
import { ref, onMounted, computed, inject } from 'vue'; import { ref, onMounted, computed, inject, provide } from 'vue';
import { useRoute, useRouter } from 'vue-router'; import { useRoute, useRouter } from 'vue-router';
import { useUserInfoStore } from '@/stores/useUserInfoStore'; import { useUserInfoStore } from '@/stores/useUserInfoStore';
import { useToastStore } from '@s/toastStore'; import { useToastStore } from '@s/toastStore';
@ -165,6 +167,8 @@
const attachment = ref(false); const attachment = ref(false);
const comments = ref([]); const comments = ref([]);
const profileImg = ref(''); const profileImg = ref('');
const isEditPushed = ref(false);
const isDeletePushed = ref(false);
const route = useRoute(); const route = useRoute();
const router = useRouter(); const router = useRouter();
@ -319,6 +323,9 @@
}); });
fetchComments(pagination.value.currentPage); fetchComments(pagination.value.currentPage);
closeAllEditTextareas();
closeAllPasswordAreas();
activeCommentBtnClass();
}; };
// //
@ -476,6 +483,9 @@
if (isUnknown) { if (isUnknown) {
togglePassword('edit'); togglePassword('edit');
closeAllEditTextareas();
closeAllPasswordAreas();
activeCommentBtnClass();
} else { } else {
router.push({ name: 'BoardEdit', params: { id: currentBoardId.value } }); router.push({ name: 'BoardEdit', params: { id: currentBoardId.value } });
} }
@ -505,11 +515,36 @@
return null; return null;
}; };
const btnState = ref({});
provide('isBtnPushed', btnState);
const activeCommentBtnClass = (targetComment = null, type = 3) => {
const target = targetComment?.commentId;
let editPush = false;
let deletePush = false;
if (targetComment) {
if (type == 1) {
editPush = true;
deletePush = false;
} else if (type == 2) {
editPush = false;
deletePush = true;
}
}
btnState.value = {
target: target,
isEditPushed: editPush,
isDeletePushed: deletePush,
};
};
// ( ) // ( )
const editComment = comment => { const editComment = comment => {
acitveButtonType(); //
password.value = ''; password.value = '';
passwordCommentAlert.value = ''; passwordCommentAlert.value = '';
//currentPasswordCommentId.value = null;
isPassword.value = false; // isPassword.value = false; //
const targetComment = findCommentById(comment.commentId, comments.value); const targetComment = findCommentById(comment.commentId, comments.value);
@ -522,27 +557,20 @@
if (isMyComment) { if (isMyComment) {
if (targetComment.isEditTextarea) { if (targetComment.isEditTextarea) {
// //
targetComment.isEditTextarea = false; targetComment.isEditTextarea = false;
currentPasswordCommentId.value = comment.commentId; currentPasswordCommentId.value = comment.commentId;
activeCommentBtnClass(targetComment, 3);
} else { } else {
// closeAllEditTextareas(); //
closeAllEditTextareas(); currentPasswordCommentId.value = null; //
currentPasswordCommentId.value = null; targetComment.isEditTextarea = true; //
// activeCommentBtnClass(targetComment, 1);
targetComment.isEditTextarea = true;
} }
} else if (isAnonymous) { } else if (isAnonymous) {
if (currentPasswordCommentId.value === comment.commentId) { if (currentPasswordCommentId.value === comment.commentId) {
// toggleCommentPassword(comment, 'edit'); //
toggleCommentPassword(comment, 'edit');
return;
} else { } else {
// closeAllEditTextareas(); //
closeAllEditTextareas();
//
targetComment.isEditTextarea = false; targetComment.isEditTextarea = false;
toggleCommentPassword(comment, 'edit'); toggleCommentPassword(comment, 'edit');
} }
@ -551,6 +579,26 @@
} }
}; };
//
const deleteComment = async comment => {
const isMyComment = comment.authorId === currentUserId.value;
//
if (unknown.value && !isMyComment) {
//
if (comment.isEditTextarea) {
comment.isEditTextarea = false;
comment.isCommentPassword = true;
toggleCommentPassword(comment, 'delete');
} else {
activeCommentBtnClass(comment, 3);
toggleCommentPassword(comment, 'delete');
}
} else {
deleteReplyComment(comment);
}
};
// //
const closeAllEditTextareas = () => { const closeAllEditTextareas = () => {
comments.value.forEach(comment => { comments.value.forEach(comment => {
@ -568,30 +616,20 @@
passwordCommentAlert.value = ''; passwordCommentAlert.value = '';
}; };
//
const deleteComment = async comment => {
const isMyComment = comment.authorId === currentUserId.value;
if (unknown.value && !isMyComment) {
if (comment.isEditTextarea) {
comment.isEditTextarea = false;
comment.isCommentPassword = true;
toggleCommentPassword(comment, 'delete');
} else {
toggleCommentPassword(comment, 'delete');
}
} else {
deleteReplyComment(comment);
}
};
// //
const toggleCommentPassword = (comment, button) => { const toggleCommentPassword = (comment, button) => {
if (lastCommentClickedButton.value === button && currentPasswordCommentId.value === comment.commentId) { if (lastCommentClickedButton.value === button && currentPasswordCommentId.value === comment.commentId) {
currentPasswordCommentId.value = null; // currentPasswordCommentId.value = null; //
password.value = ''; password.value = '';
passwordCommentAlert.value = ''; passwordCommentAlert.value = '';
activeCommentBtnClass(comment, 3);
} else { } else {
if (button == 'edit') {
activeCommentBtnClass(comment, 1);
} else if (button == 'delete') {
activeCommentBtnClass(comment, 2);
}
currentPasswordCommentId.value = comment.commentId; // currentPasswordCommentId.value = comment.commentId; //
password.value = ''; password.value = '';
passwordCommentAlert.value = ''; passwordCommentAlert.value = '';
@ -608,17 +646,49 @@
isPassword.value = false; isPassword.value = false;
boardPasswordAlert.value = ''; boardPasswordAlert.value = '';
password.value = ''; password.value = '';
acitveButtonType();
return; return;
} }
closeAllPasswordAreas(); closeAllPasswordAreas();
if (lastClickedButton.value === button) { if (lastClickedButton.value === button) {
isPassword.value = !isPassword.value; isPassword.value = !isPassword.value;
boardPasswordAlert.value = ''; boardPasswordAlert.value = '';
lastClickedButton.value = '';
acitveButtonType();
} else { } else {
isPassword.value = true; isPassword.value = true;
} lastClickedButton.value = button;
lastClickedButton.value = button; if (button == 'edit') {
acitveButtonType(1);
} else if (button == 'delete') {
acitveButtonType(2);
} else {
acitveButtonType();
}
}
};
// (, )
const acitveButtonType = type => {
//closeAllEditTextareas(); //
//inActiveCommentButtonClass(); //
//
if (type == 1) {
isEditPushed.value = true;
isDeletePushed.value = false;
//
} else if (type == 2) {
isEditPushed.value = false;
isDeletePushed.value = true;
//
} else {
isEditPushed.value = false;
isDeletePushed.value = false;
}
}; };
// //
@ -738,6 +808,7 @@
if (response.data.code === 200) { if (response.data.code === 200) {
await fetchComments(pagination.value.currentPage); await fetchComments(pagination.value.currentPage);
closeAllPasswordAreas(); closeAllPasswordAreas();
activeCommentBtnClass();
if (targetComment) { if (targetComment) {
// " ." , // " ." ,
@ -766,6 +837,7 @@
if (response.status === 200) { if (response.status === 200) {
togglePassword('close'); togglePassword('close');
fetchComments(pagination.value.currentPage); fetchComments(pagination.value.currentPage);
activeCommentBtnClass();
return; return;
// const targetComment = findCommentById(comment.commentId, comments.value); // const targetComment = findCommentById(comment.commentId, comments.value);