Calendar/src/index.ts

82 lines
2.4 KiB
TypeScript
Raw Normal View History

// 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);
}
}
/**
2025-08-09 01:16:04 +02:00
* 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 => {
});
}