댓글 수정시 공백체크

This commit is contained in:
nevermoregb 2025-03-14 01:53:35 +09:00
parent 2ec81f274d
commit 84f5cf4412
3 changed files with 42 additions and 4 deletions

View File

@ -35,6 +35,7 @@
<div class="mt-6"> <div class="mt-6">
<template v-if="comment.isEditTextarea"> <template v-if="comment.isEditTextarea">
<textarea v-model="localEditedContent" class="form-control"></textarea> <textarea v-model="localEditedContent" class="form-control"></textarea>
<span v-if="editCommentAlert" class="invalid-feedback d-block text-start">{{ editCommentAlert }}</span>
<div class="mt-2 d-flex justify-content-end"> <div class="mt-2 d-flex justify-content-end">
<SaveBtn class="btn btn-primary" @click="submitEdit"></SaveBtn> <SaveBtn class="btn btn-primary" @click="submitEdit"></SaveBtn>
</div> </div>
@ -60,7 +61,7 @@
</template> </template>
<script setup> <script setup>
import { defineProps, defineEmits, ref, computed, watch } from 'vue'; import { defineProps, defineEmits, ref, computed, watch, inject } from 'vue';
import BoardProfile from './BoardProfile.vue'; import BoardProfile from './BoardProfile.vue';
import BoardCommentArea from './BoardCommentArea.vue'; import BoardCommentArea from './BoardCommentArea.vue';
import PlusButton from '../button/PlusBtn.vue'; import PlusButton from '../button/PlusBtn.vue';
@ -109,6 +110,7 @@
password: { password: {
type: String, type: String,
}, },
editCommentAlert: String,
}); });
// emits // emits
@ -121,6 +123,7 @@
'submitEdit', 'submitEdit',
'cancelEdit', 'cancelEdit',
'update:password', 'update:password',
'inputDetector',
]); ]);
const filterInput = event => { const filterInput = event => {
@ -165,6 +168,14 @@
}, },
); );
// text
watch(
() => localEditedContent.value,
newVal => {
emit('inputDetector');
},
);
// watch(() => props.comment.isDeleted, () => { // watch(() => props.comment.isDeleted, () => {
// console.log("BoardComment - isDeleted :", newVal); // console.log("BoardComment - isDeleted :", newVal);

View File

@ -11,14 +11,16 @@
:passwordCommentAlert="passwordCommentAlert || ''" :passwordCommentAlert="passwordCommentAlert || ''"
:currentPasswordCommentId="currentPasswordCommentId" :currentPasswordCommentId="currentPasswordCommentId"
:password="password" :password="password"
:editCommentAlert="editCommentAlert[comment.commentId]"
@editClick="handleEditClick" @editClick="handleEditClick"
@deleteClick="handleDeleteClick" @deleteClick="handleDeleteClick"
@submitPassword="submitPassword" @submitPassword="submitPassword"
@submitComment="submitComment" @submitComment="submitComment"
@submitEdit="handleSubmitEdit" @submitEdit="(comment, editedContent) => $emit('submitEdit', comment, editedContent)"
@cancelEdit="handleCancelEdit" @cancelEdit="handleCancelEdit"
@updateReaction="reactionData => handleUpdateReaction(reactionData, comment.commentId, comment.boardId)" @updateReaction="reactionData => handleUpdateReaction(reactionData, comment.commentId, comment.boardId)"
@update:password="updatePassword" @update:password="updatePassword"
@inputDetector="$emit('inputDetector')"
> >
<!-- 대댓글 --> <!-- 대댓글 -->
<template #reply> <template #reply>
@ -35,14 +37,16 @@
:currentPasswordCommentId="currentPasswordCommentId" :currentPasswordCommentId="currentPasswordCommentId"
:passwordCommentAlert="passwordCommentAlert" :passwordCommentAlert="passwordCommentAlert"
:password="password" :password="password"
:editCommentAlert="editCommentAlert[child.commentId]"
@editClick="handleReplyEditClick" @editClick="handleReplyEditClick"
@deleteClick="$emit('deleteClick', child)" @deleteClick="$emit('deleteClick', child)"
@submitEdit="(comment, editedContent) => $emit('submitEdit', comment, editedContent)" @submitEdit="(comment, editedContent) => $emit('submitEdit', comment, editedContent, child.commentId)"
@cancelEdit="$emit('cancelEdit', child)" @cancelEdit="$emit('cancelEdit', child)"
@submitComment="submitComment" @submitComment="submitComment"
@updateReaction="handleUpdateReaction" @updateReaction="handleUpdateReaction"
@submitPassword="$emit('submitPassword', child, password)" @submitPassword="$emit('submitPassword', child, password)"
@update:password="$emit('update:password', $event)" @update:password="$emit('update:password', $event)"
@inputDetector="$emit('inputDetector')"
/> />
</li> </li>
</ul> </ul>
@ -95,6 +99,7 @@
index: { index: {
type: Number, type: Number,
}, },
editCommentAlert: Object,
}); });
const emit = defineEmits([ const emit = defineEmits([
@ -106,6 +111,7 @@
'clearPassword', 'clearPassword',
'submitEdit', 'submitEdit',
'update:password', 'update:password',
'inputDetector',
]); ]);
const submitComment = replyData => { const submitComment = replyData => {

View File

@ -109,6 +109,7 @@
:passwordCommentAlert="passwordCommentAlert" :passwordCommentAlert="passwordCommentAlert"
:currentPasswordCommentId="currentPasswordCommentId" :currentPasswordCommentId="currentPasswordCommentId"
:password="password" :password="password"
:editCommentAlert="editCommentAlert"
@editClick="editComment" @editClick="editComment"
@deleteClick="deleteComment" @deleteClick="deleteComment"
@updateReaction="handleCommentReaction" @updateReaction="handleCommentReaction"
@ -118,6 +119,7 @@
@cancelEdit="handleCancelEdit" @cancelEdit="handleCancelEdit"
@submitEdit="handleSubmitEdit" @submitEdit="handleSubmitEdit"
@update:password="updatePassword" @update:password="updatePassword"
@inputDetector="inputDetector"
/> />
<Pagination v-if="pagination.pages" v-bind="pagination" @update:currentPage="handlePageChange" /> <Pagination v-if="pagination.pages" v-bind="pagination" @update:currentPage="handlePageChange" />
</div> </div>
@ -133,11 +135,13 @@
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 } from 'vue'; import { ref, onMounted, computed, inject } 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';
import axios from '@api'; import axios from '@api';
const $common = inject('common');
// //
const profileName = ref(''); const profileName = ref('');
const boardTitle = ref('제목 없음'); const boardTitle = ref('제목 없음');
@ -161,6 +165,7 @@
const unknown = computed(() => profileName.value === '익명'); const unknown = computed(() => profileName.value === '익명');
const currentUserId = computed(() => userStore?.user?.id); // id const currentUserId = computed(() => userStore?.user?.id); // id
const authorId = ref(''); // id const authorId = ref(''); // id
const editCommentAlert = ref({}); //,
const isAuthor = computed(() => currentUserId.value === authorId.value); const isAuthor = computed(() => currentUserId.value === authorId.value);
const commentsWithAuthStatus = computed(() => { const commentsWithAuthStatus = computed(() => {
@ -234,6 +239,7 @@
const inputCheck = () => { const inputCheck = () => {
passwordAlert.value = ''; passwordAlert.value = '';
}; };
// //
const fetchBoardDetails = async () => { const fetchBoardDetails = async () => {
const response = await axios.get(`board/${currentBoardId.value}`); const response = await axios.get(`board/${currentBoardId.value}`);
@ -437,6 +443,11 @@
} }
}; };
// ,
const inputDetector = () => {
editCommentAlert.value = {};
};
// //
const editClick = unknown => { const editClick = unknown => {
const isUnknown = unknown?.unknown ?? false; const isUnknown = unknown?.unknown ?? false;
@ -721,6 +732,7 @@
// //
const handleSubmitEdit = async (comment, editedContent) => { const handleSubmitEdit = async (comment, editedContent) => {
if (!checkValidation(comment, editedContent)) return;
togglePassword(); togglePassword();
try { try {
const response = await axios.put(`board/comment/${comment.commentId}`, { const response = await axios.put(`board/comment/${comment.commentId}`, {
@ -744,6 +756,15 @@
} }
}; };
// , .
const checkValidation = (comment, content) => {
if (!$common.isNotEmpty(content)) {
editCommentAlert.value[comment.commentId] = '내용을 입력하세요';
return false;
}
return true;
};
// ( ) // ( )
const handleCancelEdit = comment => { const handleCancelEdit = comment => {
const targetComment = findCommentById(comment.commentId, comments.value); const targetComment = findCommentById(comment.commentId, comments.value);