From b2c81dc16318c3f627d277af61870c8c5b154489 Mon Sep 17 00:00:00 2001 From: "Janus C. H. Knudsen" Date: Wed, 17 Dec 2025 19:41:11 +0100 Subject: [PATCH] Refactor calendar event constants and imports Separates calendar-specific events into a dedicated CalendarEvents constant Removes calendar command events from CoreEvents Updates imports and event bus references across related files --- src/v2/constants/CoreEvents.ts | 10 +--------- src/v2/core/CalendarApp.ts | 14 +++++++------- src/v2/core/CalendarEvents.ts | 12 ++++++++++++ src/v2/demo/DemoApp.ts | 16 ++++++++-------- 4 files changed, 28 insertions(+), 24 deletions(-) create mode 100644 src/v2/core/CalendarEvents.ts diff --git a/src/v2/constants/CoreEvents.ts b/src/v2/constants/CoreEvents.ts index d4c9894..9c25100 100644 --- a/src/v2/constants/CoreEvents.ts +++ b/src/v2/constants/CoreEvents.ts @@ -67,13 +67,5 @@ export const CoreEvents = { AUDIT_LOGGED: 'audit:logged', // Rendering events - EVENTS_RENDERED: 'events:rendered', - - // Calendar command events - CALENDAR_CMD_NAVIGATE_PREV: 'calendar:cmd:navigate:prev', - CALENDAR_CMD_NAVIGATE_NEXT: 'calendar:cmd:navigate:next', - CALENDAR_CMD_DRAWER_TOGGLE: 'calendar:cmd:drawer:toggle', - CALENDAR_CMD_RENDER: 'calendar:cmd:render', - CALENDAR_CMD_WORKWEEK_CHANGE: 'calendar:cmd:workweek:change', - CALENDAR_CMD_VIEW_UPDATE: 'calendar:cmd:view:update' + EVENTS_RENDERED: 'events:rendered' } as const; diff --git a/src/v2/core/CalendarApp.ts b/src/v2/core/CalendarApp.ts index 43b3c27..af44af2 100644 --- a/src/v2/core/CalendarApp.ts +++ b/src/v2/core/CalendarApp.ts @@ -15,7 +15,7 @@ import { ResourceService } from '../storage/resources/ResourceService'; import { ViewConfigService } from '../storage/viewconfigs/ViewConfigService'; import { IWorkweekPreset } from '../types/SettingsTypes'; import { IEventBus } from '../types/CalendarTypes'; -import { CoreEvents } from '../constants/CoreEvents'; +import { CalendarEvents } from './CalendarEvents'; export class CalendarApp { private animator!: NavigationAnimator; @@ -79,33 +79,33 @@ export class CalendarApp { private setupEventListeners(): void { // Navigation commands via EventBus - this.eventBus.on(CoreEvents.CALENDAR_CMD_NAVIGATE_PREV, () => { + this.eventBus.on(CalendarEvents.CMD_NAVIGATE_PREV, () => { this.handleNavigatePrev(); }); - this.eventBus.on(CoreEvents.CALENDAR_CMD_NAVIGATE_NEXT, () => { + this.eventBus.on(CalendarEvents.CMD_NAVIGATE_NEXT, () => { this.handleNavigateNext(); }); // Drawer toggle via EventBus - this.eventBus.on(CoreEvents.CALENDAR_CMD_DRAWER_TOGGLE, () => { + this.eventBus.on(CalendarEvents.CMD_DRAWER_TOGGLE, () => { this.headerDrawerManager.toggle(); }); // Render command via EventBus - this.eventBus.on(CoreEvents.CALENDAR_CMD_RENDER, ((e: CustomEvent) => { + this.eventBus.on(CalendarEvents.CMD_RENDER, ((e: CustomEvent) => { const { viewId } = e.detail; this.handleRenderCommand(viewId); }) as EventListener); // Workweek change via EventBus - this.eventBus.on(CoreEvents.CALENDAR_CMD_WORKWEEK_CHANGE, ((e: CustomEvent) => { + this.eventBus.on(CalendarEvents.CMD_WORKWEEK_CHANGE, ((e: CustomEvent) => { const { presetId } = e.detail; this.handleWorkweekChange(presetId); }) as EventListener); // View update via EventBus - this.eventBus.on(CoreEvents.CALENDAR_CMD_VIEW_UPDATE, ((e: CustomEvent) => { + this.eventBus.on(CalendarEvents.CMD_VIEW_UPDATE, ((e: CustomEvent) => { const { type, values } = e.detail; this.handleViewUpdate(type, values); }) as EventListener); diff --git a/src/v2/core/CalendarEvents.ts b/src/v2/core/CalendarEvents.ts new file mode 100644 index 0000000..d52b45d --- /dev/null +++ b/src/v2/core/CalendarEvents.ts @@ -0,0 +1,12 @@ +/** + * CalendarEvents - Command and status events for CalendarApp + */ +export const CalendarEvents = { + // Command events (host → calendar) + CMD_NAVIGATE_PREV: 'calendar:cmd:navigate:prev', + CMD_NAVIGATE_NEXT: 'calendar:cmd:navigate:next', + CMD_DRAWER_TOGGLE: 'calendar:cmd:drawer:toggle', + CMD_RENDER: 'calendar:cmd:render', + CMD_WORKWEEK_CHANGE: 'calendar:cmd:workweek:change', + CMD_VIEW_UPDATE: 'calendar:cmd:view:update' +} as const; diff --git a/src/v2/demo/DemoApp.ts b/src/v2/demo/DemoApp.ts index a36ecf0..e20faf9 100644 --- a/src/v2/demo/DemoApp.ts +++ b/src/v2/demo/DemoApp.ts @@ -5,7 +5,7 @@ import { CalendarApp } from '../core/CalendarApp'; import { DateService } from '../core/DateService'; import { ResourceService } from '../storage/resources/ResourceService'; import { IEventBus } from '../types/CalendarTypes'; -import { CoreEvents } from '../constants/CoreEvents'; +import { CalendarEvents } from '../core/CalendarEvents'; export class DemoApp { private container!: HTMLElement; @@ -50,16 +50,16 @@ export class DemoApp { this.setupStatusListeners(); // Initial render - this.eventBus.emit(CoreEvents.CALENDAR_CMD_RENDER, { viewId: this.currentView }); + this.eventBus.emit(CalendarEvents.CMD_RENDER, { viewId: this.currentView }); } private setupNavigation(): void { document.getElementById('btn-prev')!.onclick = () => { - this.eventBus.emit(CoreEvents.CALENDAR_CMD_NAVIGATE_PREV); + this.eventBus.emit(CalendarEvents.CMD_NAVIGATE_PREV); }; document.getElementById('btn-next')!.onclick = () => { - this.eventBus.emit(CoreEvents.CALENDAR_CMD_NAVIGATE_NEXT); + this.eventBus.emit(CalendarEvents.CMD_NAVIGATE_NEXT); }; } @@ -74,7 +74,7 @@ export class DemoApp { if (view) { this.currentView = view; this.updateSelectorVisibility(); - this.eventBus.emit(CoreEvents.CALENDAR_CMD_RENDER, { viewId: view }); + this.eventBus.emit(CalendarEvents.CMD_RENDER, { viewId: view }); } }); }); @@ -88,7 +88,7 @@ export class DemoApp { private setupDrawerToggle(): void { document.getElementById('btn-drawer')!.onclick = () => { - this.eventBus.emit(CoreEvents.CALENDAR_CMD_DRAWER_TOGGLE); + this.eventBus.emit(CalendarEvents.CMD_DRAWER_TOGGLE); }; } @@ -96,7 +96,7 @@ export class DemoApp { const workweekSelect = document.getElementById('workweek-select') as HTMLSelectElement; workweekSelect?.addEventListener('change', () => { const presetId = workweekSelect.value; - this.eventBus.emit(CoreEvents.CALENDAR_CMD_WORKWEEK_CHANGE, { presetId }); + this.eventBus.emit(CalendarEvents.CMD_WORKWEEK_CHANGE, { presetId }); }); } @@ -119,7 +119,7 @@ export class DemoApp { container.addEventListener('change', () => { const checked = container.querySelectorAll('input:checked') as NodeListOf; const values = Array.from(checked).map(cb => cb.value); - this.eventBus.emit(CoreEvents.CALENDAR_CMD_VIEW_UPDATE, { type: 'resource', values }); + this.eventBus.emit(CalendarEvents.CMD_VIEW_UPDATE, { type: 'resource', values }); }); }