Kumi
b88a998c9a
Introduce state persistence to example to save and load Kanblendar state using localStorage, enhancing user experience by remembering their tasks and settings across sessions. Implement a new 'taskChanged' custom event to trigger state saving whenever tasks are created, moved, edited, or deleted. This ensures state consistency and reduces the risk of data loss. Refactor to attach Kanblendar instance to the window object for global access in example.
20 lines
No EOL
704 B
JavaScript
20 lines
No EOL
704 B
JavaScript
document.addEventListener('DOMContentLoaded', () => {
|
|
window.kanblendar = new Kanblendar();
|
|
const createTaskBtn = document.getElementById('createTaskBtn');
|
|
createTaskBtn.addEventListener('click', () => window.kanblendar.openModal());
|
|
|
|
function saveState() {
|
|
const serializedState = kanblendar.serialize();
|
|
localStorage.setItem('kanblendarState', serializedState);
|
|
console.log('State saved!');
|
|
}
|
|
|
|
document.addEventListener('taskChanged', saveState);
|
|
|
|
const serializedState = localStorage.getItem('kanblendarState');
|
|
if (serializedState) {
|
|
kanblendar.deserialize(serializedState);
|
|
console.log('State loaded on page load!');
|
|
}
|
|
|
|
}); |