From 668957a30be1faf806358f808b40212f4551509e Mon Sep 17 00:00:00 2001 From: Till-JS <101404291+Till-JS@users.noreply.github.com> Date: Sun, 14 Dec 2025 21:18:50 +0100 Subject: [PATCH] refactor(calendar): extract birthday popover logic into composable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Create useBirthdayPopover composable to eliminate duplicated birthday popover state and handlers across DayView, WeekView, and MonthView. Changes: - Add useBirthdayPopover.svelte.ts composable - Update DayView to use the composable - Update WeekView to use the composable - Update MonthView to use the composable - Export from composables/index.ts This removes ~40 lines of duplicated code across the three views. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .../lib/components/calendar/DayView.svelte | 34 ++++--------- .../lib/components/calendar/MonthView.svelte | 24 +++------ .../lib/components/calendar/WeekView.svelte | 32 +++--------- .../apps/web/src/lib/composables/index.ts | 3 ++ .../composables/useBirthdayPopover.svelte.ts | 49 +++++++++++++++++++ 5 files changed, 76 insertions(+), 66 deletions(-) create mode 100644 apps/calendar/apps/web/src/lib/composables/useBirthdayPopover.svelte.ts diff --git a/apps/calendar/apps/web/src/lib/components/calendar/DayView.svelte b/apps/calendar/apps/web/src/lib/components/calendar/DayView.svelte index e8dc910f3..5a501906a 100644 --- a/apps/calendar/apps/web/src/lib/components/calendar/DayView.svelte +++ b/apps/calendar/apps/web/src/lib/components/calendar/DayView.svelte @@ -6,12 +6,9 @@ import { searchStore } from '$lib/stores/search.svelte'; import { todosStore, type Task } from '$lib/stores/todos.svelte'; import { eventContextMenuStore } from '$lib/stores/eventContextMenu.svelte'; - import { birthdaysStore, type BirthdayEvent } from '$lib/stores/birthdays.svelte'; + import { birthdaysStore } from '$lib/stores/birthdays.svelte'; import BirthdayPopover from '$lib/components/birthday/BirthdayPopover.svelte'; - import { - useVisibleHours, - useCurrentTimeIndicator, - } from '$lib/composables/useVisibleHours.svelte'; + import { useVisibleHours, useCurrentTimeIndicator, useBirthdayPopover } from '$lib/composables'; import { toDate } from '$lib/utils/eventDateHelpers'; import { HOUR_HEIGHT_PX, SNAP_INTERVAL_MINUTES } from '$lib/utils/calendarConstants'; import { @@ -102,9 +99,8 @@ let blockAllDayEvents = $derived(allDayEvents.filter((e) => getEventDisplayMode(e) === 'block')); - // Birthday Popover State - let selectedBirthday = $state(null); - let birthdayPopoverPosition = $state<{ x: number; y: number }>({ x: 0, y: 0 }); + // Birthday Popover (using composable) + const birthdayPopover = useBirthdayPopover(); // Get birthdays for current day (if enabled in settings) let birthdays = $derived.by(() => { @@ -112,18 +108,6 @@ return birthdaysStore.getBirthdaysForDay(viewStore.currentDate); }); - // Handle birthday click - show popover - function handleBirthdayClick(birthday: BirthdayEvent, e: MouseEvent) { - e.stopPropagation(); - selectedBirthday = birthday; - birthdayPopoverPosition = { x: e.clientX, y: e.clientY }; - } - - // Close birthday popover - function closeBirthdayPopover() { - selectedBirthday = null; - } - // ============================================================================ // Drag & Drop State // ============================================================================ @@ -744,7 +728,7 @@ {#each birthdays as birthday}