From 83145d9b2a76233d9e8cc83282d90d9ad57e3996 Mon Sep 17 00:00:00 2001 From: Leo Vasanko Date: Sat, 23 Aug 2025 11:21:39 -0600 Subject: [PATCH] Settings now work immediately. --- src/components/CalendarHeader.vue | 21 ++++---- src/components/CalendarView.vue | 35 +++++++++---- src/components/SettingsDialog.vue | 86 ++++++++++++------------------- 3 files changed, 67 insertions(+), 75 deletions(-) diff --git a/src/components/CalendarHeader.vue b/src/components/CalendarHeader.vue index afacf15..b3fde2b 100644 --- a/src/components/CalendarHeader.vue +++ b/src/components/CalendarHeader.vue @@ -12,10 +12,10 @@ const props = defineProps({ const calendarStore = useCalendarStore() -// Emits: year-change -> { year, scrollTop } +// Emits year-change events const emit = defineEmits(['year-change']) -const baseDate = new Date(1970, 0, 4 + calendarStore.config.first_day) +const baseDate = computed(() => new Date(1970, 0, 4 + calendarStore.config.first_day)) const WEEK_MS = 7 * 24 * 60 * 60 * 1000 const topVirtualWeek = computed(() => { @@ -24,9 +24,9 @@ const topVirtualWeek = computed(() => { }) const currentYear = computed(() => { - const weekStart = new Date(baseDate) + const weekStart = new Date(baseDate.value) weekStart.setDate(weekStart.getDate() + topVirtualWeek.value * 7) - // ISO anchor: Thursday of current calendar week + // ISO anchor Thursday const anchor = new Date(weekStart) anchor.setDate(anchor.getDate() + ((4 - anchor.getDay() + 7) % 7)) return isoWeekInfo(anchor).year @@ -36,11 +36,10 @@ function virtualWeekOf(d) { const o = (d.getDay() - calendarStore.config.first_day + 7) % 7 const fd = new Date(d) fd.setDate(d.getDate() - o) - return Math.floor((fd - baseDate) / WEEK_MS) + return Math.floor((fd - baseDate.value) / WEEK_MS) } function isoWeekMonday(isoYear, isoWeek) { - // Monday of ISO week 1 const jan4 = new Date(isoYear, 0, 4) const week1Mon = new Date(jan4) week1Mon.setDate(week1Mon.getDate() - ((week1Mon.getDay() + 6) % 7)) @@ -54,16 +53,16 @@ function changeYear(y) { y = Math.round(Math.max(calendarStore.minYear, Math.min(calendarStore.maxYear, y))) if (y === currentYear.value) return const vw = topVirtualWeek.value - // Fraction within current row for smooth vertical position preservation + // Fraction within current row const weekStartScroll = (vw - props.minVirtualWeek) * props.rowHeight const frac = Math.max(0, Math.min(1, (props.scrollTop - weekStartScroll) / props.rowHeight)) - // Derive current ISO week via anchor Thursday - const curCalWeekStart = new Date(baseDate) + // Anchor Thursday of current calendar week + const curCalWeekStart = new Date(baseDate.value) curCalWeekStart.setDate(curCalWeekStart.getDate() + vw * 7) const curAnchorThu = new Date(curCalWeekStart) curAnchorThu.setDate(curAnchorThu.getDate() + ((4 - curAnchorThu.getDay() + 7) % 7)) let { week: isoW } = isoWeekInfo(curAnchorThu) - // Build Monday of that ISO week in target year; fallback if week absent (53) + // Build Monday of ISO week let weekMon = isoWeekMonday(y, isoW) if (isoWeekInfo(weekMon).year !== y) { isoW-- @@ -80,7 +79,7 @@ function changeYear(y) { } const weekdayNames = computed(() => { - // Get Monday-first names, then reorder by first day, then add weekend info + // Reorder names & weekend flags const mondayFirstNames = getLocalizedWeekdayNames() const sundayFirstNames = [mondayFirstNames[6], ...mondayFirstNames.slice(0, 6)] const reorderedNames = reorderByFirstDay(sundayFirstNames, calendarStore.config.first_day) diff --git a/src/components/CalendarView.vue b/src/components/CalendarView.vue index 4ccf351..9abf190 100644 --- a/src/components/CalendarView.vue +++ b/src/components/CalendarView.vue @@ -1,5 +1,5 @@