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
This commit is contained in:
Janus C. H. Knudsen 2025-12-17 19:41:11 +01:00
parent 66dfe9f2ef
commit b2c81dc163
4 changed files with 28 additions and 24 deletions

View file

@ -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;

View file

@ -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);

View file

@ -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;

View file

@ -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<HTMLInputElement>;
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 });
});
}