diff --git a/apps/calendar/apps/web/src/lib/components/calendar/DateStrip.svelte b/apps/calendar/apps/web/src/lib/components/calendar/DateStrip.svelte index f357b7a8d..413c58e47 100644 --- a/apps/calendar/apps/web/src/lib/components/calendar/DateStrip.svelte +++ b/apps/calendar/apps/web/src/lib/components/calendar/DateStrip.svelte @@ -16,24 +16,9 @@ let viewRange = $derived(viewStore.viewRange); let currentDate = $derived(viewStore.currentDate); - // Check if a day is within the current view range - function isInViewRange(day: Date): boolean { - return isWithinInterval(day, { start: viewRange.start, end: viewRange.end }); - } - - // Check if day is the first in the view range - function isFirstInRange(day: Date): boolean { - return isSameDay(day, viewRange.start); - } - - // Check if day is the last in the view range - function isLastInRange(day: Date): boolean { - return isSameDay(day, viewRange.end); - } - // How many days to load in each direction const DAYS_BUFFER = 60; - const LOAD_THRESHOLD = 20; // Load more when within this many days of edge + const LOAD_THRESHOLD = 20; // Generate initial days centered around current date let startDate = $state(subDays(startOfDay(new Date()), DAYS_BUFFER)); @@ -67,7 +52,6 @@ async function scrollToDate(date: Date) { await tick(); - // First ensure the date is in our range const targetDate = startOfDay(date); if (targetDate < startDate) { startDate = subDays(targetDate, DAYS_BUFFER); @@ -103,17 +87,11 @@ isLoadingMore = true; if (direction === 'past') { - // Save scroll position relative to a reference element - const firstVisibleDay = scrollContainer?.querySelector('.day-item'); const scrollLeftBefore = scrollContainer?.scrollLeft || 0; - startDate = subDays(startDate, DAYS_BUFFER); await tick(); - - // Restore scroll position - if (firstVisibleDay && scrollContainer) { - const newScrollLeft = scrollLeftBefore + DAYS_BUFFER * 54; // 54px is approximate day width (52px + gap) - scrollContainer.scrollLeft = newScrollLeft; + if (scrollContainer) { + scrollContainer.scrollLeft = scrollLeftBefore + DAYS_BUFFER * 54; } } else { endDate = addDays(endDate, DAYS_BUFFER); @@ -125,7 +103,7 @@ function checkTodayVisibility() { if (!scrollContainer) return; - const todayElement = scrollContainer.querySelector('.day-item.today'); + const todayElement = scrollContainer.querySelector('[data-is-today="true"]'); if (!todayElement) { isTodayVisible = false; return; @@ -134,7 +112,6 @@ const containerRect = scrollContainer.getBoundingClientRect(); const todayRect = todayElement.getBoundingClientRect(); - // Check if today element is within the visible scroll area isTodayVisible = todayRect.left >= containerRect.left - 20 && todayRect.right <= containerRect.right + 20; } @@ -142,34 +119,25 @@ function handleScroll() { if (!scrollContainer || isLoadingMore) return; - // Check if today is visible checkTodayVisibility(); - const { scrollLeft, scrollWidth, clientWidth } = scrollContainer; - const scrollRight = scrollWidth - scrollLeft - clientWidth; - - // Calculate approximate day index from scroll position - const dayWidth = 54; // approximate (52px + gap) + const { scrollLeft, clientWidth } = scrollContainer; + const dayWidth = 54; const visibleDayIndex = Math.floor(scrollLeft / dayWidth); const totalDays = days.length; - // Load more past days if (visibleDayIndex < LOAD_THRESHOLD) { loadMoreDays('past'); } - // Load more future days if (totalDays - visibleDayIndex - Math.floor(clientWidth / dayWidth) < LOAD_THRESHOLD) { loadMoreDays('future'); } } - // Get month label for a date (shown at month boundaries) function getMonthLabel(day: Date, index: number): string | null { - // Show month label on first day of month or first day in view if (day.getDate() === 1 || index === 0) { if (day.getMonth() === 0 && day.getDate() === 1) { - // Show year for January 1st return format(day, 'MMM yyyy', { locale: de }); } return format(day, 'MMM', { locale: de }); @@ -178,26 +146,22 @@ } onMount(() => { - // Initial scroll to current date scrollToDate(viewStore.currentDate); });