feat: state.settings.moderatorsPerDay with localStorage persistence
This commit is contained in:
1 parent
a825a63961
commit
ad680ae1f6
2 files changed
+9
-2
No files matched your search
@@ -8,7 +8,8 @@ const STORAGE_KEY = 'morning-planner-state';
|
|||||||
export const state = {
|
export const state = {
|
||||||
employees: [],
|
employees: [],
|
||||||
calendar: { holidays: [], companyClosures: [] },
|
calendar: { holidays: [], companyClosures: [] },
|
||||||
history: []
|
history: [],
|
||||||
|
settings: { moderatorsPerDay: 1 }
|
||||||
};
|
};
|
||||||
|
|
||||||
// Load persisted state from localStorage on startup
|
// Load persisted state from localStorage on startup
|
||||||
@@ -19,6 +20,10 @@ try {
|
|||||||
if (Array.isArray(parsed.employees)) state.employees = parsed.employees;
|
if (Array.isArray(parsed.employees)) state.employees = parsed.employees;
|
||||||
if (parsed.calendar) state.calendar = parsed.calendar;
|
if (parsed.calendar) state.calendar = parsed.calendar;
|
||||||
if (Array.isArray(parsed.history)) state.history = parsed.history;
|
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 {
|
} catch {
|
||||||
// Corrupt storage — start fresh
|
// Corrupt storage — start fresh
|
||||||
@@ -30,7 +35,8 @@ export function saveState() {
|
|||||||
localStorage.setItem(STORAGE_KEY, JSON.stringify({
|
localStorage.setItem(STORAGE_KEY, JSON.stringify({
|
||||||
employees: state.employees,
|
employees: state.employees,
|
||||||
calendar: state.calendar,
|
calendar: state.calendar,
|
||||||
history: state.history
|
history: state.history,
|
||||||
|
settings: state.settings
|
||||||
}));
|
}));
|
||||||
} catch {
|
} catch {
|
||||||
// Storage full or unavailable — silently ignore
|
// Storage full or unavailable — silently ignore
|
||||||
|
|||||||
@@ -79,6 +79,7 @@ export function renderDataTab() {
|
|||||||
state.employees = loaded.employees;
|
state.employees = loaded.employees;
|
||||||
state.calendar = loaded.calendar;
|
state.calendar = loaded.calendar;
|
||||||
state.history = loaded.history;
|
state.history = loaded.history;
|
||||||
|
state.settings = loaded.settings;
|
||||||
saveState();
|
saveState();
|
||||||
alert('Daten erfolgreich geladen.');
|
alert('Daten erfolgreich geladen.');
|
||||||
renderDataTab();
|
renderDataTab();
|
||||||
|
|||||||
Reference in new issue
Block a user