Skip to content

Commit 3a5421e

Browse files
committed
feat(View): Implement changing comment status
1 parent 218b4ea commit 3a5421e

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

src/components/VToasts.vue

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
>
1111
<div class="d-flex justify-content-between align-items-center">
1212
<div class="toast-body" v-html="item.body"></div>
13-
1413
<button
1514
v-if="item.clearable"
1615
type="button"

src/composables/comments.composable.js

+12-1
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,29 @@ export const useFetchComments = () => {
1515
startLoading();
1616
return CommentsService.getAll(config)
1717
.then((response) => {
18-
comments.value = response.data.map(item=>({...item,status:"PENDING"}));
18+
comments.value = response.data.map((item) => ({ ...item, status: "PENDING" }));
1919
return response;
2020
})
2121
.finally(() => {
2222
endLoading();
2323
});
2424
};
2525

26+
const changeStatus = (id, status) => {
27+
const updatedItemIndex = comments.value.findIndex((comment) => comment.id === id);
28+
comments.value[updatedItemIndex].status = status;
29+
30+
// comments.value = comments.value.map((comment) => {
31+
// if (comment.id === id) return { ...comment, status };
32+
// else return comment;
33+
// });
34+
};
35+
2636
return {
2737
comments,
2838
commentsIsLoading: isLoading,
2939
commentsKeyById,
3040
fetchComments,
41+
changeStatus,
3142
};
3243
};

src/views/CommentsView.vue

+14-5
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
{{ $t("Confirmed") }}
3636
</span>
3737
<span v-if="item.status === 'REJECTED'">
38-
{{ $("Rejected") }}
38+
{{ $t("Rejected") }}
3939
</span>
4040
</template>
4141
</VColumn>
@@ -45,7 +45,7 @@
4545
<button class="btn btn-danger btn-sm" @click="handleRejectComment(item)">
4646
<i class="bi-ban" />
4747
</button>
48-
<button class="btn btn-success btn-sm z-3" data-bs-toggle="tooltip" data-bs-placement="top"
48+
<button class="btn btn-success btn-sm z-3" data-bs-toggle="tooltip" data-bs-placement="top" @click="handleConfirmComment(item.id)"
4949
data-bs-title="Tooltip on top">
5050
<i class="bi-check-circle" />
5151
</button>
@@ -91,13 +91,17 @@ import VModal from "@/components/VModal.vue";
9191
import { useFetchComments } from "@/composables/comments.composable";
9292
import { useApplyFilters } from "@/composables/filter.composable";
9393
import useFetchPost from "@/composables/posts.composable";
94+
import { useToast } from "@/composables/toast.composable";
95+
import ThemeColor from "@/enums/ThemeColor";
9496
import StorageService from "@/services/storage.service";
9597
import { computed, reactive, ref, watch } from "vue";
9698
9799
export default {
98100
name: "CommentsView",
99101
setup() {
100-
const { comments, commentsIsLoading, fetchComments } = useFetchComments();
102+
const { showToast } = useToast()
103+
104+
const { comments, commentsIsLoading, fetchComments , changeStatus: changeCommentStatus} = useFetchComments();
101105
fetchComments({});
102106
103107
const { post, postIsLoading, fetchPost } = useFetchPost();
@@ -112,11 +116,14 @@ export default {
112116
rejectComment.comment = rejectedComment;
113117
rejectComment.modalIsOpen = true;
114118
};
119+
const handleConfirmComment = (id)=>{
120+
changeCommentStatus(id,'CONFIRMED')
121+
}
115122
116123
const handleFetchPost = async (id) => {
117124
try {
118125
postModalIsOpen.value = true;
119-
await fetchPost(id);
126+
fetchPost(id).then(res => console.log("res", res)).catch(err => console.log("err", err));
120127
} catch {
121128
postModalIsOpen.value = false;
122129
}
@@ -169,7 +176,8 @@ export default {
169176
};
170177
171178
const handleConfirmRejection = () => {
172-
// doing rejection here
179+
changeCommentStatus(rejectComment.comment.id , "REJECTED")
180+
showToast({ body: "undo", theme: ThemeColor.WARNING, title: "Deleting", duration: 3000 })
173181
rejectComment.comment = null
174182
rejectComment.modalIsOpen = false
175183
}
@@ -186,6 +194,7 @@ export default {
186194
handleRejectComment,
187195
handleConfirmRejection,
188196
rejectComment,
197+
handleConfirmComment
189198
};
190199
},
191200
components: {

0 commit comments

Comments
 (0)