Feat: Add comment delete feature

This commit is contained in:
jhynsoo 2024-05-23 15:25:59 +09:00
parent 4a65a80b40
commit 7a39717a5e
2 changed files with 14 additions and 5 deletions

View File

@ -1,13 +1,15 @@
<script setup> <script setup>
import { ref } from 'vue'; import { ref } from 'vue';
import TextButton from '../common/TextButton.vue'; import TextButton from '../common/TextButton.vue';
import { deleteComment } from '@/api/comment';
const { comment } = defineProps({ comment: Object }); const { comment, userId } = defineProps({ comment: Object, userId: String });
const isDeleted = ref(false); const isDeleted = ref(false);
function handleDelete() { function handleDelete() {
console.log('delete', comment.id); deleteComment(comment.id).then(() => {
// TODO: add api call isDeleted.value = true;
});
} }
</script> </script>
@ -18,7 +20,7 @@ function handleDelete() {
<div class="nickname">{{ comment.nickname }}</div> <div class="nickname">{{ comment.nickname }}</div>
<div class="date">{{ comment.date }}</div> <div class="date">{{ comment.date }}</div>
</div> </div>
<div v-if="!comment.isAuthor" class="control"> <div v-if="comment.authorId === userId" class="control">
<TextButton @click="handleDelete">삭제</TextButton> <TextButton @click="handleDelete">삭제</TextButton>
</div> </div>
</div> </div>

View File

@ -1,12 +1,19 @@
<script setup> <script setup>
import { useMemberStore } from '@/stores/memberStore';
import CommentItem from './CommentItem.vue'; import CommentItem from './CommentItem.vue';
const { comments } = defineProps({ comments: Array }); const { comments } = defineProps({ comments: Array });
const { userId } = useMemberStore();
</script> </script>
<template> <template>
<ul> <ul>
<CommentItem v-for="comment in comments" :key="comment.id" :comment="comment" /> <CommentItem
v-for="comment in comments"
:key="comment.id"
:comment="comment"
:userId="userId"
/>
</ul> </ul>
</template> </template>