feat: auto-persist state to localStorage on every change

This commit is contained in:
Ferdinand
2026-04-08 14:17:24 +02:00
parent 6ecf3e4409
commit dca82fe381
4 changed files with 47 additions and 7 deletions

View File

@@ -1,4 +1,4 @@
import { state } from './app.js';
import { state, saveState } from './app.js';
import { createEmployee, removeEmployee } from './data.js';
import { readEmployeeNames } from './excel.js';
@@ -58,6 +58,7 @@ export function renderEmployees() {
return;
}
nameInput.value = '';
saveState();
refreshList();
});
@@ -76,6 +77,7 @@ export function renderEmployees() {
}
}
e.target.value = '';
saveState();
refreshList();
});
}
@@ -119,6 +121,7 @@ function refreshList() {
removeBtn.addEventListener('click', () => {
removeEmployee(state, emp.id);
saveState();
refreshList();
});
@@ -162,6 +165,7 @@ function renderConstraintEditor(empId) {
const idx = arr.indexOf(day);
if (idx >= 0) arr.splice(idx, 1); else arr.push(day);
btn.classList.toggle('active');
saveState();
});
group.appendChild(btn);
}
@@ -184,6 +188,7 @@ function renderConstraintEditor(empId) {
input.addEventListener('change', () => {
const val = input.value.trim();
emp.constraints[constraintKey] = val === '' ? null : parseInt(val, 10);
saveState();
});
row.append(lbl, input);
return row;
@@ -215,6 +220,7 @@ function renderConstraintEditor(empId) {
addVacBtn.addEventListener('click', () => {
emp.constraints.vacations.push({ from: '', to: '' });
saveState();
renderVacationList(empId);
});
}
@@ -240,7 +246,7 @@ function renderVacationList(empId) {
const fromInput = document.createElement('input');
fromInput.type = 'date';
fromInput.value = v.from;
fromInput.addEventListener('change', () => { emp.constraints.vacations[i].from = fromInput.value; });
fromInput.addEventListener('change', () => { emp.constraints.vacations[i].from = fromInput.value; saveState(); });
const sep = document.createElement('span');
sep.textContent = 'bis';
@@ -248,13 +254,14 @@ function renderVacationList(empId) {
const toInput = document.createElement('input');
toInput.type = 'date';
toInput.value = v.to;
toInput.addEventListener('change', () => { emp.constraints.vacations[i].to = toInput.value; });
toInput.addEventListener('change', () => { emp.constraints.vacations[i].to = toInput.value; saveState(); });
const delBtn = document.createElement('button');
delBtn.type = 'button';
delBtn.textContent = '✕';
delBtn.addEventListener('click', () => {
emp.constraints.vacations.splice(i, 1);
saveState();
renderVacationList(empId);
});