fix: handle tasks without due times appropriately

Ensures tasks without due times are moved to a non-timed section rather than attempting to update their location based on an undefined value. This change prevents errors related to missing due time values and improves overall task management experience.
This commit is contained in:
Kumi 2024-07-30 13:45:30 +02:00
parent 83471f8820
commit cc4989cac4
Signed by: kumi
GPG key ID: ECBCC9082395383F

View file

@ -295,7 +295,7 @@ class Kanblendar {
event.preventDefault(); event.preventDefault();
const title = document.getElementById('kanblendar-taskTitle').value; const title = document.getElementById('kanblendar-taskTitle').value;
const description = document.getElementById('kanblendar-taskDescription').value; const description = document.getElementById('kanblendar-taskDescription').value;
const dueTime = document.getElementById('kanblendar-taskDueTime').value; const dueTime = document.getElementById('kanblendar-taskDueTime').value || null;
const column = document.getElementById('kanblendar-taskColumn').value; const column = document.getElementById('kanblendar-taskColumn').value;
const notifyBefore = parseInt(document.getElementById('kanblendar-taskNotify').value, 10); const notifyBefore = parseInt(document.getElementById('kanblendar-taskNotify').value, 10);
@ -308,12 +308,20 @@ class Kanblendar {
this.currentTask.dataset.column = column; this.currentTask.dataset.column = column;
this.currentTask.dataset.notifyBefore = notifyBefore; this.currentTask.dataset.notifyBefore = notifyBefore;
this.moveTaskToColumn(this.currentTask, column); this.moveTaskToColumn(this.currentTask, column);
if (dueTime) {
this.updateTaskLocation(this.currentTask, dueTime); this.updateTaskLocation(this.currentTask, dueTime);
} else {
this.moveTaskToNonTimedSection(this.currentTask, column);
}
this.cancelNotification(this.currentTask.id); this.cancelNotification(this.currentTask.id);
} else { } else {
newTask = this.createTaskElement(title, description, dueTime, column, notifyBefore); newTask = this.createTaskElement(title, description, dueTime, column, notifyBefore);
this.moveTaskToColumn(newTask, column); // Correctly move to the selected column this.moveTaskToColumn(newTask, column);
if (dueTime) {
this.updateTaskLocation(newTask, dueTime); this.updateTaskLocation(newTask, dueTime);
} else {
this.moveTaskToNonTimedSection(newTask, column);
}
} }
if (dueTime && notifyBefore >= 0) { if (dueTime && notifyBefore >= 0) {
@ -324,6 +332,13 @@ class Kanblendar {
this.closeModalFunc(); this.closeModalFunc();
} }
moveTaskToNonTimedSection(task, column) {
const columnTasks = document.getElementById(`${column}-tasks`);
if (columnTasks) {
columnTasks.appendChild(task);
}
}
createTaskElement(title, description, dueTime, column, notifyBefore) { createTaskElement(title, description, dueTime, column, notifyBefore) {
const id = `task-${Date.now()}`; const id = `task-${Date.now()}`;
const newTask = document.createElement('div'); const newTask = document.createElement('div');