From 99cd68ad439d4491663da539b1e4cc09b49332e2 Mon Sep 17 00:00:00 2001 From: kolaente Date: Wed, 13 Jul 2022 16:51:56 +0200 Subject: [PATCH] fix(kanban): make sure the task position is calculated correctly The very first task in a bucket always has the position 0. Now, if we move another task in front of that, it too gets the position 0 assigned. That means the two first tasks now both have the position 0 and are not sorted correctly. This commit fixes that: When moving a task to the very first position it checks if the task now on the second position also has position 0 assigned to it. If that's the case, we'll now update that task's position as well to make sure it has another position than 0. --- src/views/list/ListKanban.vue | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/views/list/ListKanban.vue b/src/views/list/ListKanban.vue index 78361989c2..12f197baa7 100644 --- a/src/views/list/ListKanban.vue +++ b/src/views/list/ListKanban.vue @@ -408,7 +408,6 @@ export default defineComponent({ // of the drop target works all the time. const bucketIndex = parseInt(e.to.dataset.bucketIndex) - const newBucket = this.buckets[bucketIndex] // HACK: @@ -429,11 +428,28 @@ export default defineComponent({ const taskAfter = newBucket.tasks[newTaskIndex + 1] ?? null const newTask = cloneDeep(task) // cloning the task to avoid vuex store mutations - newTask.bucketId = newBucket.id, - newTask.kanbanPosition = calculateItemPosition(taskBefore !== null ? taskBefore.kanbanPosition : null, taskAfter !== null ? taskAfter.kanbanPosition : null) + newTask.bucketId = newBucket.id + newTask.kanbanPosition = calculateItemPosition( + taskBefore !== null ? taskBefore.kanbanPosition : null, + taskAfter !== null ? taskAfter.kanbanPosition : null, + ) try { await this.$store.dispatch('tasks/update', newTask) + + // Make sure the first and second task don't both get position 0 assigned + if(newTaskIndex === 0 && taskAfter.kanbanPosition === 0) { + console.log('first', taskAfter.id, taskAfter.kanbanPosition) + const taskAfterAfter = newBucket.tasks[newTaskIndex + 2] ?? null + const newTaskAfter = cloneDeep(taskAfter) // cloning the task to avoid vuex store mutations + newTaskAfter.bucketId = newBucket.id + newTaskAfter.kanbanPosition = calculateItemPosition( + 0, + taskAfterAfter !== null ? taskAfterAfter.kanbanPosition : null, + ) + + await this.$store.dispatch('tasks/update', newTaskAfter) + } } finally { this.taskUpdating[task.id] = false this.oneTaskUpdating = false