kanblendar/example.js
Kumi b88a998c9a
feat: add state persistence and task change events
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.
2024-07-30 14:09:38 +02:00

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!');
}
});