feat(mobile): week plan always starts today and moves forward

This commit is contained in:
Sven (AAMOS AI)
2026-08-16 22:36:22 +07:00
parent 05c6cf9e04
commit 8fe8900722
+6 -8
View File
@@ -59,13 +59,6 @@ function addDays(d: Date, n: number): Date {
copy.setDate(copy.getDate() + n); copy.setDate(copy.getDate() + n);
return copy; return copy;
} }
function startOfWeekMonday(d: Date): Date {
const copy = new Date(d);
const dow = (copy.getDay() + 6) % 7;
copy.setDate(copy.getDate() - dow);
copy.setHours(0, 0, 0, 0);
return copy;
}
function cap(s: string): string { function cap(s: string): string {
return s.length ? s[0]!.toUpperCase() + s.slice(1) : s; return s.length ? s[0]!.toUpperCase() + s.slice(1) : s;
} }
@@ -78,7 +71,12 @@ export default function PlanScreen() {
const todayKey = toKey(new Date()); const todayKey = toKey(new Date());
const selected = useMemo(() => new Date(`${selectedKey}T00:00:00`), [selectedKey]); const selected = useMemo(() => new Date(`${selectedKey}T00:00:00`), [selectedKey]);
const monday = useMemo(() => startOfWeekMonday(selected), [selected]); // Veckoplanen startar alltid idag och går 7 dagar framåt (aldrig bakåt i tiden).
const monday = useMemo(() => {
const d = new Date();
d.setHours(0, 0, 0, 0);
return d;
}, []);
const mondayKey = toKey(monday); const mondayKey = toKey(monday);
const weekDays = useMemo(() => Array.from({ length: 7 }, (_, i) => addDays(monday, i)), [monday]); const weekDays = useMemo(() => Array.from({ length: 7 }, (_, i) => addDays(monday, i)), [monday]);