crud 성공하자 2
댓글 수정과 삭제... 삭제가 더 간편해 보여서 삭제부터 진행한다.
// 문서에 있는 모든 삭제 버튼에 이벤트 등록
const deleteBtns = document.querySelectorAll(".comment-delete-btn");
deleteBtns.forEach(btn => {
btn.addEventListener("click", deleteComment);
});
const deleteComment = async event => {
const commentID = event.target.name;
const ok = window.confirm("정말 삭제하시겠습니까?");
if (ok) {
try {
await deleteDoc(doc(dbService, "comment", commentID));
// 댓글 삭제 완료되면 페이지 다시 불러오기
const path = window.location.hash.replace("#", "/");
viewPost(path).then(() => {
viewComments(path);
});
} catch (error) {
console.error(error);
}
}
};