WIP on master
This commit is contained in:
parent
b6ab1ff50e
commit
80aaab46f2
25 changed files with 6291 additions and 927 deletions
|
|
@ -2,83 +2,43 @@ import { IEventBus, CalendarEvent } from '../types/CalendarTypes';
|
|||
import { CoreEvents } from '../constants/CoreEvents';
|
||||
import { CalendarConfig } from '../core/CalendarConfig';
|
||||
import { DateService } from '../utils/DateService';
|
||||
|
||||
interface RawEventData {
|
||||
id: string;
|
||||
title: string;
|
||||
start: string | Date;
|
||||
end: string | Date;
|
||||
type : string;
|
||||
color?: string;
|
||||
allDay?: boolean;
|
||||
[key: string]: unknown;
|
||||
}
|
||||
import { IEventRepository } from '../repositories/IEventRepository';
|
||||
|
||||
/**
|
||||
* EventManager - Event lifecycle and CRUD operations
|
||||
* Handles data loading and event management
|
||||
* Handles event management and CRUD operations
|
||||
*/
|
||||
export class EventManager {
|
||||
|
||||
private events: CalendarEvent[] = [];
|
||||
private rawData: RawEventData[] | null = null;
|
||||
private dateService: DateService;
|
||||
private config: CalendarConfig;
|
||||
private repository: IEventRepository;
|
||||
|
||||
constructor(
|
||||
private eventBus: IEventBus,
|
||||
dateService: DateService,
|
||||
config: CalendarConfig
|
||||
config: CalendarConfig,
|
||||
repository: IEventRepository
|
||||
) {
|
||||
this.dateService = dateService;
|
||||
this.config = config;
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load event data from JSON file
|
||||
* Load event data from repository
|
||||
*/
|
||||
public async loadData(): Promise<void> {
|
||||
try {
|
||||
await this.loadMockData();
|
||||
this.events = await this.repository.loadEvents();
|
||||
} catch (error) {
|
||||
console.error('Failed to load event data:', error);
|
||||
this.events = [];
|
||||
this.rawData = null;
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Optimized mock data loading
|
||||
*/
|
||||
private async loadMockData(): Promise<void> {
|
||||
const jsonFile = 'data/mock-events.json';
|
||||
|
||||
const response = await fetch(jsonFile);
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to load mock events: ${response.status} ${response.statusText}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
// Store raw data and process in one operation
|
||||
this.rawData = data;
|
||||
this.events = this.processCalendarData(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process raw event data and convert to CalendarEvent objects
|
||||
*/
|
||||
private processCalendarData(data: RawEventData[]): CalendarEvent[] {
|
||||
return data.map((event): CalendarEvent => ({
|
||||
...event,
|
||||
start: new Date(event.start),
|
||||
end: new Date(event.end),
|
||||
type : event.type,
|
||||
allDay: event.allDay || false,
|
||||
syncStatus: 'synced' as const
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get events with optional copying for performance
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue