fix(tasks): retain task IDs on reload

Added an optional 'id' parameter to the createTaskElement method to retain task IDs when reloading tasks from storage. This ensures task IDs remain consistent across sessions, preventing issues related to task identification and management.
This commit is contained in:
Kumi 2024-07-31 11:51:26 +02:00
parent 5c5473ad7b
commit 482576ed32
Signed by: kumi
GPG key ID: ECBCC9082395383F

View file

@ -353,12 +353,12 @@ class Kanblendar {
}
}
createTaskElement(title, description, dueTime, column, notifyBefore) {
const id = `task-${Date.now()}`;
createTaskElement(title, description, dueTime, column, notifyBefore, id = null) {
const taskId = id || `task-${Date.now()}`;
const newTask = document.createElement('div');
newTask.classList.add('kanblendar-task');
newTask.setAttribute('draggable', 'true');
newTask.setAttribute('id', id);
newTask.setAttribute('id', taskId);
newTask.dataset.dueTime = dueTime;
newTask.dataset.column = column;
newTask.dataset.notifyBefore = notifyBefore;
@ -368,7 +368,7 @@ class Kanblendar {
`;
newTask.addEventListener('dragstart', (e) => this.dragStart(e));
newTask.addEventListener('click', (e) => this.openModal(newTask)); // Add click event to open modal for editing
this.tasks.set(id, { title, description, dueTime, column, notifyBefore });
this.tasks.set(taskId, { title, description, dueTime, column, notifyBefore });
return newTask;
}
@ -507,9 +507,8 @@ class Kanblendar {
const tasksArray = JSON.parse(serializedData);
tasksArray.forEach(taskData => {
const { id, title, description, dueTime, column, notifyBefore } = taskData;
const taskElement = this.createTaskElement(title, description, dueTime, column, notifyBefore);
taskElement.id = id; // Restore original ID
this.tasks.set(id, { title, description, dueTime, notifyBefore });
const taskElement = this.createTaskElement(title, description, dueTime, column, notifyBefore, id);
this.tasks.set(id, { title, description, dueTime, column, notifyBefore });
this.moveTaskToColumn(taskElement, column);
if (dueTime) {
this.updateTaskLocation(taskElement, dueTime);