diff --git a/src/components/tasks/TaskDetailView.vue b/src/components/tasks/TaskDetailView.vue index b3356aed..57c7fe2b 100644 --- a/src/components/tasks/TaskDetailView.vue +++ b/src/components/tasks/TaskDetailView.vue @@ -488,7 +488,7 @@ this.$nextTick(() => this.$refs[fieldName].$el.focus()) }, deleteTask() { - this.taskService.delete(this.task) + this.$store.dispatch('tasks/delete', this.task) .then(() => { this.success({message: 'The task been deleted successfully.'}, this) router.back() diff --git a/src/store/modules/kanban.js b/src/store/modules/kanban.js index 9a331295..4a4201d8 100644 --- a/src/store/modules/kanban.js +++ b/src/store/modules/kanban.js @@ -67,6 +67,26 @@ export default { const bi = filterObject(state.buckets, b => b.id === task.bucketId) state.buckets[bi].tasks.push(task) }, + removeTaskInBucket(state, task) { + // If this gets invoked without any tasks actually loaded, we can save the hassle of finding the task + if (state.buckets.length === 0) { + return + } + + for (const b in state.buckets) { + if (state.buckets[b].id === task.bucketId) { + for (const t in state.buckets[b].tasks) { + if (state.buckets[b].tasks[t].id === task.id) { + const bucket = state.buckets[b] + bucket.tasks.splice(t, 1) + Vue.set(state.buckets, b, bucket) + return + } + } + return + } + } + } }, getters: { getTaskById: state => id => { diff --git a/src/store/modules/tasks.js b/src/store/modules/tasks.js index a8b7207a..4bd9b65a 100644 --- a/src/store/modules/tasks.js +++ b/src/store/modules/tasks.js @@ -19,6 +19,17 @@ export default { return Promise.reject(e) }) }, + delete(ctx, task) { + const taskService = new TaskService() + return taskService.delete(task) + .then(t => { + ctx.commit('kanban/removeTaskInBucket', task, {root: true}) + return Promise.resolve(t) + }) + .catch(e => { + return Promise.reject(e) + }) + }, // Adds a task attachment in store. // This is an action to be able to commit other mutations addTaskAttachment(ctx, {taskId, attachment}) {