Calendar/src/index.ts
Janus C. H. Knudsen 6bbf2d8adb Refactors date handling with DateService
Replaces DateCalculator with DateService for improved date and time operations, including timezone handling.

This change enhances the calendar's accuracy and flexibility in managing dates, especially concerning timezone configurations.
It also corrects a typo in the `allDay` dataset attribute.
2025-10-03 20:50:40 +02:00

82 lines
No EOL
2.4 KiB
TypeScript

// Main entry point for Calendar Plantempus
import { eventBus } from './core/EventBus';
import { calendarConfig } from './core/CalendarConfig';
import { CalendarTypeFactory } from './factories/CalendarTypeFactory';
import { ManagerFactory } from './factories/ManagerFactory';
import { URLManager } from './utils/URLManager';
import { CalendarManagers } from './types/ManagerTypes';
/**
* Handle deep linking functionality after managers are initialized
*/
async function handleDeepLinking(managers: CalendarManagers): Promise<void> {
try {
const urlManager = new URLManager(eventBus);
const eventId = urlManager.parseEventIdFromURL();
if (eventId) {
console.log(`Deep linking to event ID: ${eventId}`);
// Wait a bit for managers to be fully ready
setTimeout(() => {
const success = managers.eventManager.navigateToEvent(eventId);
if (!success) {
console.warn(`Deep linking failed: Event with ID ${eventId} not found`);
}
}, 500);
}
} catch (error) {
console.warn('Deep linking failed:', error);
}
}
/**
* Initialize the calendar application with simple direct calls
*/
async function initializeCalendar(): Promise<void> {
try {
// Use the singleton calendar configuration
const config = calendarConfig;
// Initialize the CalendarTypeFactory before creating managers
CalendarTypeFactory.initialize();
// Create managers using factory pattern
const managerFactory = ManagerFactory.getInstance();
const managers = managerFactory.createManagers(eventBus);
// Enable debug mode for development
eventBus.setDebug(true);
// Initialize all managers
await managerFactory.initializeManagers(managers);
// Handle deep linking after managers are initialized
await handleDeepLinking(managers);
// Expose to window for debugging (with proper typing)
(window as Window & {
calendarDebug?: {
eventBus: typeof eventBus;
} & CalendarManagers;
}).calendarDebug = {
eventBus,
...managers
};
} catch (error) {
throw error;
}
}
// Initialize when DOM is ready - now handles async properly
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', () => {
initializeCalendar().catch(error => {
});
});
} else {
initializeCalendar().catch(error => {
});
}