feat: state.settings.moderatorsPerDay with localStorage persistence

This commit is contained in:
ferdi2go committed 2026-04-28 10:48:58 +00:00
1 parent a825a63961
commit ad680ae1f6
2 files changed
+9 -2

No files matched your search

+8 -2
View File
@@ -8,7 +8,8 @@ const STORAGE_KEY = 'morning-planner-state';
export const state = {
employees: [],
calendar: { holidays: [], companyClosures: [] },
history: []
history: [],
settings: { moderatorsPerDay: 1 }
};
// Load persisted state from localStorage on startup
@@ -19,6 +20,10 @@ try {
if (Array.isArray(parsed.employees)) state.employees = parsed.employees;
if (parsed.calendar) state.calendar = parsed.calendar;
if (Array.isArray(parsed.history)) state.history = parsed.history;
if (parsed.settings && Number.isInteger(parsed.settings.moderatorsPerDay)
&& parsed.settings.moderatorsPerDay >= 1 && parsed.settings.moderatorsPerDay <= 5) {
state.settings = { moderatorsPerDay: parsed.settings.moderatorsPerDay };
}
}
} catch {
// Corrupt storage — start fresh
@@ -30,7 +35,8 @@ export function saveState() {
localStorage.setItem(STORAGE_KEY, JSON.stringify({
employees: state.employees,
calendar: state.calendar,
history: state.history
history: state.history,
settings: state.settings
}));
} catch {
// Storage full or unavailable — silently ignore