Calendar/src/index.ts

81 lines
2.4 KiB
TypeScript
Raw Normal View History

// Main entry point for Calendar Plantempus
import { eventBus } from './core/EventBus.js';
2025-08-07 00:15:44 +02:00
import { calendarConfig } from './core/CalendarConfig.js';
import { CalendarTypeFactory } from './factories/CalendarTypeFactory.js';
import { ManagerFactory } from './factories/ManagerFactory.js';
import { DateCalculator } from './utils/DateCalculator.js';
import { URLManager } from './utils/URLManager.js';
/**
* Handle deep linking functionality after managers are initialized
*/
async function handleDeepLinking(managers: any): 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 DateCalculator with config first
DateCalculator.initialize(config);
// 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
(window as any).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 => {
});
}