2025-07-24 22:17:38 +02:00
|
|
|
// Main entry point for Calendar Plantempus
|
2025-09-23 20:44:15 +02:00
|
|
|
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';
|
2025-09-04 00:16:35 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Handle deep linking functionality after managers are initialized
|
|
|
|
|
*/
|
2025-09-23 20:44:15 +02:00
|
|
|
async function handleDeepLinking(managers: CalendarManagers): Promise<void> {
|
2025-09-04 00:16:35 +02:00
|
|
|
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-07-24 22:17:38 +02:00
|
|
|
|
|
|
|
|
/**
|
2025-08-09 01:16:04 +02:00
|
|
|
* Initialize the calendar application with simple direct calls
|
2025-07-24 22:17:38 +02:00
|
|
|
*/
|
2025-08-09 00:31:44 +02:00
|
|
|
async function initializeCalendar(): Promise<void> {
|
2025-07-24 22:17:38 +02:00
|
|
|
|
2025-08-09 00:31:44 +02:00
|
|
|
try {
|
|
|
|
|
// Use the singleton calendar configuration
|
|
|
|
|
const config = calendarConfig;
|
|
|
|
|
|
|
|
|
|
// Initialize the CalendarTypeFactory before creating managers
|
|
|
|
|
CalendarTypeFactory.initialize();
|
|
|
|
|
|
2025-08-17 23:44:30 +02:00
|
|
|
// Create managers using factory pattern
|
|
|
|
|
const managerFactory = ManagerFactory.getInstance();
|
2025-09-03 20:04:47 +02:00
|
|
|
const managers = managerFactory.createManagers(eventBus);
|
2025-08-09 00:31:44 +02:00
|
|
|
|
|
|
|
|
// Enable debug mode for development
|
|
|
|
|
eventBus.setDebug(true);
|
|
|
|
|
|
2025-08-17 23:44:30 +02:00
|
|
|
// Initialize all managers
|
|
|
|
|
await managerFactory.initializeManagers(managers);
|
2025-08-09 00:31:44 +02:00
|
|
|
|
2025-09-04 00:16:35 +02:00
|
|
|
// Handle deep linking after managers are initialized
|
|
|
|
|
await handleDeepLinking(managers);
|
2025-08-17 23:44:30 +02:00
|
|
|
|
2025-09-23 20:44:15 +02:00
|
|
|
// Expose to window for debugging (with proper typing)
|
|
|
|
|
(window as Window & {
|
|
|
|
|
calendarDebug?: {
|
|
|
|
|
eventBus: typeof eventBus;
|
|
|
|
|
} & CalendarManagers;
|
|
|
|
|
}).calendarDebug = {
|
2025-08-17 23:44:30 +02:00
|
|
|
eventBus,
|
|
|
|
|
...managers
|
|
|
|
|
};
|
2025-08-09 00:31:44 +02:00
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
|
throw error;
|
|
|
|
|
}
|
2025-07-24 22:17:38 +02:00
|
|
|
}
|
|
|
|
|
|
2025-08-09 00:31:44 +02:00
|
|
|
// Initialize when DOM is ready - now handles async properly
|
2025-07-24 22:17:38 +02:00
|
|
|
if (document.readyState === 'loading') {
|
2025-08-09 00:31:44 +02:00
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
|
|
|
initializeCalendar().catch(error => {
|
2025-08-31 22:39:09 +02:00
|
|
|
});
|
2025-08-09 00:31:44 +02:00
|
|
|
});
|
2025-07-24 22:17:38 +02:00
|
|
|
} else {
|
2025-08-09 00:31:44 +02:00
|
|
|
initializeCalendar().catch(error => {
|
|
|
|
|
});
|
2025-07-24 22:17:38 +02:00
|
|
|
}
|