feat: reset planner and range on user change for improved state management

This commit is contained in:
Daniel Volz
2025-12-29 20:29:46 +01:00
parent 85c411ba88
commit cf37400d34
+8 -1
View File
@@ -273,6 +273,9 @@ function AppContent() {
} else { } else {
setRange({ start: toInputValue(todayIso()), end: toInputValue(plusDaysIso(3)) }); setRange({ start: toInputValue(todayIso()), end: toInputValue(plusDaysIso(3)) });
} }
} else {
setPlannerRows([]);
setRange({ start: toInputValue(todayIso()), end: toInputValue(plusDaysIso(3)) });
} }
}, [user?.id]); }, [user?.id]);
@@ -570,10 +573,14 @@ function AppContent() {
const pastDays = useMemo(() => groupedSchedule.filter(d => d.isPast), [groupedSchedule]); const pastDays = useMemo(() => groupedSchedule.filter(d => d.isPast), [groupedSchedule]);
const futureDays = useMemo(() => groupedSchedule.filter(d => !d.isPast).slice(0, scheduleDays), [groupedSchedule, scheduleDays]); const futureDays = useMemo(() => groupedSchedule.filter(d => !d.isPast).slice(0, scheduleDays), [groupedSchedule, scheduleDays]);
// Load medications and settings when user changes (or on initial mount)
useEffect(() => { useEffect(() => {
loadMeds(); loadMeds();
loadSettings(); loadSettings();
}, []); // Reset planner when user changes
setPlannerRows([]);
setRange({ start: toInputValue(todayIso()), end: toInputValue(plusDaysIso(3)) });
}, [user?.id]);
function loadMeds() { function loadMeds() {
setLoading(true); setLoading(true);