Refactors calendar architecture for month view

Prepares the calendar component for month view implementation
by introducing a strategy pattern for view management,
splitting configuration settings, and consolidating events
into a core set. It also removes dead code and enforces type safety,
improving overall code quality and maintainability.

Addresses critical issues identified in the code review,
laying the groundwork for efficient feature addition.
This commit is contained in:
Janus Knudsen 2025-08-20 19:42:13 +02:00
parent 7d513600d8
commit 3ddc6352f2
17 changed files with 1347 additions and 428 deletions

View file

@ -3,9 +3,9 @@
import { eventBus } from '../core/EventBus';
import { calendarConfig } from '../core/CalendarConfig';
import { EventTypes } from '../constants/EventTypes';
import { StateEvents } from '../types/CalendarState';
import { DateCalculator } from '../utils/DateCalculator';
import { ResourceCalendarData } from '../types/CalendarTypes';
import { AllDayEvent } from '../types/EventTypes';
import { GridRenderer } from '../renderers/GridRenderer';
import { GridStyleManager } from '../renderers/GridStyleManager';
@ -25,7 +25,7 @@ export class GridManager {
private container: HTMLElement | null = null;
private grid: HTMLElement | null = null;
private currentWeek: Date | null = null;
private allDayEvents: any[] = []; // Store all-day events for current week
private allDayEvents: AllDayEvent[] = []; // Store all-day events for current week
private resourceData: ResourceCalendarData | null = null; // Store resource data for resource calendar
private gridRenderer: GridRenderer;
private styleManager: GridStyleManager;
@ -111,17 +111,6 @@ export class GridManager {
this.updateAllDayEvents(detail.events);
});
// Handle data loaded for resource mode
eventBus.on(StateEvents.DATA_LOADED, (e: Event) => {
const detail = (e as CustomEvent).detail;
console.log(`GridManager: Received DATA_LOADED`);
if (detail.data && detail.data.calendarMode === 'resource') {
// Resource data will be passed in the state event
// For now just update grid styles
this.styleManager.updateGridStyles(this.resourceData);
}
});
// Handle grid clicks
this.setupGridInteractions();
@ -176,7 +165,7 @@ export class GridManager {
/**
* Update all-day events data and re-render if needed
*/
private updateAllDayEvents(events: any[]): void {
private updateAllDayEvents(events: AllDayEvent[]): void {
if (!this.currentWeek) return;
// Filter all-day events for current week