feat: auto-persist state to localStorage on every change
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { state } from './app.js';
|
||||
import { state, saveState } from './app.js';
|
||||
import { getWorkdays, generatePlan } from './algorithm.js';
|
||||
import { toggleHoliday, toggleClosure, addHistoryEntries, removeHistoryEntry } from './data.js';
|
||||
import { exportSchedule, downloadBlob } from './excel.js';
|
||||
@@ -99,6 +99,7 @@ export function renderCalendar() {
|
||||
const historyWithoutMonth = state.history.filter(h => !h.date.startsWith(prefix));
|
||||
currentPlan = generatePlan(workdays, state.employees, historyWithoutMonth);
|
||||
addHistoryEntries(state, currentPlan);
|
||||
saveState();
|
||||
renderGrid(wrapper, exportBtn);
|
||||
});
|
||||
|
||||
@@ -184,6 +185,7 @@ function renderGrid(wrapper, exportBtn) {
|
||||
removeBtn.addEventListener('click', () => {
|
||||
if (isHoliday) toggleHoliday(state, iso);
|
||||
else toggleClosure(state, iso);
|
||||
saveState();
|
||||
renderGrid(wrapper, exportBtn);
|
||||
});
|
||||
tag.appendChild(removeBtn);
|
||||
@@ -217,6 +219,7 @@ function renderGrid(wrapper, exportBtn) {
|
||||
removeHistoryEntry(state, iso);
|
||||
currentPlan = currentPlan.filter(a => a.date !== iso);
|
||||
}
|
||||
saveState();
|
||||
exportBtn.style.display = currentPlan.length > 0 ? 'inline-block' : 'none';
|
||||
});
|
||||
|
||||
@@ -230,13 +233,13 @@ function renderGrid(wrapper, exportBtn) {
|
||||
ftBtn.type = 'button';
|
||||
ftBtn.textContent = 'FT';
|
||||
ftBtn.style.cssText = 'font-size:9px;padding:1px 4px';
|
||||
ftBtn.addEventListener('click', () => { toggleHoliday(state, iso); renderGrid(wrapper, exportBtn); });
|
||||
ftBtn.addEventListener('click', () => { toggleHoliday(state, iso); saveState(); renderGrid(wrapper, exportBtn); });
|
||||
|
||||
const buBtn = document.createElement('button');
|
||||
buBtn.type = 'button';
|
||||
buBtn.textContent = 'BU';
|
||||
buBtn.style.cssText = 'font-size:9px;padding:1px 4px';
|
||||
buBtn.addEventListener('click', () => { toggleClosure(state, iso); renderGrid(wrapper, exportBtn); });
|
||||
buBtn.addEventListener('click', () => { toggleClosure(state, iso); saveState(); renderGrid(wrapper, exportBtn); });
|
||||
|
||||
btnRow.append(ftBtn, buBtn);
|
||||
cell.appendChild(btnRow);
|
||||
|
||||
Reference in New Issue
Block a user