async removeRoom(context, roomID) {
const room = db.collection("rooms").doc(roomID);
const messages = room.collection("messages").onSnapshot(doSnapshot);
await room.delete();
function doSnapshot(snapshot) {
snapshot.docs.forEach(async doc => {
await room
.collection("messages")
.doc(doc.id)
.delete();
});
messages();
}
}
import Vue from "vue";
const actions = {
requestConfirmation(context, { props, component }) {
const Component = () => import(`../components/${component}Component.vue`);
return new Promise((resolve, reject) => {
const dialog = new Vue({
methods: {
actionHandler(fn, arg) {
return function() {
fn(arg);
dialog.$destroy();
dialog.$el.remove();
};
}
},
render(h) {
return h(Component, {
props,
on: {
confirm: data => {
this.actionHandler(resolve, data)();
},
cancel: this.actionHandler(reject, new Error("Action cancelled"))
}
});
}
}).$mount();
document.getElementById("app").appendChild(dialog.$el);
});
}
};
export default {
namespaced: true,
actions
};
async removeRoom() {
try {
await this.$store.dispatch("utils/requestConfirmation", {
props: { message: "¿Remove room?" },
component: "ConfirmationModal"
});
await this.$store.dispatch("rooms/removeRoom", this.id);
this.$toast.success("Room removed");
this.$router.push({ name: "home" });
} catch (error) {
this.$toast.error(error.message);
}
},