Save After Every State Change
Save After Every State Change
Saving only once is not enough. The stored value must change whenever tasks changes.
Find the three places where this module’s previous work changes the task state:
- after a new task is pushed into
tasks - after a task is removed with
filter() - after a task’s
statusis changed during a drop
Call saveTasks() immediately after each state change and before the board is rendered again.
For example, task creation should follow this order:
tasks.push(newTask);
saveTasks();
renderTasks();
Deletion should follow the same idea:
tasks = tasks.filter((task) => task.id !== id);
saveTasks();
renderTasks();
And after drag-and-drop changes a task’s status:
task.status = newStatus;
saveTasks();
renderTasks();
The important point is not the exact placement of the function. It is that every successful state change is persisted before the UI is redrawn.
Checkpoint
Create a task, delete a task, and move a task to another column.
After each action, inspect the kanbanTasks value in Local Storage. It should reflect the latest board state.