From 2b5dbada07424e8abdc357eb07177c0d1dfed7ef Mon Sep 17 00:00:00 2001 From: Kumi Date: Wed, 31 Jul 2024 10:57:51 +0200 Subject: [PATCH] fix: ensure task due time updates correctly on drop Refactored time slot handling to avoid updating task due time when startTime is not valid. This prevents potential misalignment of task due times when tasks are dropped outside of defined slots. Also added missing dueTime update in the tasks map for synchronization. Adjustments ensure more consistent task scheduling and improved user interaction. --- kanblendar.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/kanblendar.js b/kanblendar.js index a633fdc..9b63a3b 100644 --- a/kanblendar.js +++ b/kanblendar.js @@ -255,17 +255,25 @@ class Kanblendar { // Update the task's due time if dropped in a time slot and the current due time is not valid for that slot if (dropTarget.classList.contains('kanblendar-time-slot')) { const startTime = dropTarget.dataset.startTime; - const dueTime = new Date(task.dataset.dueTime); + const slotStartTime = new Date(`${this.config.currentDate}T${startTime}:00`); const slotEndTime = this.addMinutes(slotStartTime, this.config.interval); - if (!(dueTime >= slotStartTime && dueTime <= slotEndTime)) { + if (startTime) { + const dueTime = new Date(task.dataset.dueTime); + + if (!(dueTime >= slotStartTime && dueTime <= slotEndTime)) { + task.dataset.dueTime = slotStartTime.toISOString(); + } + } else { task.dataset.dueTime = slotStartTime.toISOString(); } } - // Update the task's column in the tasks map + + // Update the task in the tasks map this.tasks.get(task.id).column = dropTarget.id.replace('-tasks', ''); + this.tasks.get(task.id).dueTime = task.dataset.dueTime; this.adjustTimeSlotHeights(); // Adjust heights after dropping a task }