Calendar/src/types/CalendarTypes.ts
Janus Knudsen 0ea4e47324 Refactors calendar type to calendar mode
Updates the codebase to utilize `CalendarMode` instead of the deprecated `CalendarType`.

Simplifies `CalendarConfig` by removing legacy methods and related type aliases, enhancing code maintainability and clarity.

Improves event rendering by ensuring `GRID_RENDERED` events include explicit start and end dates, preventing errors and ensuring correct data filtering.
2025-08-20 21:51:49 +02:00

146 lines
No EOL
3.3 KiB
TypeScript

// Calendar type definitions
// Time period view types (how much time to display)
export type ViewPeriod = 'day' | 'week' | 'month';
// Calendar mode types (how to organize the data)
export type CalendarMode = 'date' | 'resource';
// Type aliases
export type CalendarView = ViewPeriod;
export type SyncStatus = 'synced' | 'pending' | 'error';
export interface Resource {
name: string;
displayName: string;
avatarUrl: string;
employeeId: string;
events: CalendarEvent[];
}
export interface ResourceCalendarData {
date: string;
resources: Resource[];
}
export interface RenderContext {
container: HTMLElement;
startDate: Date;
endDate: Date;
}
export interface CalendarEvent {
id: string;
title: string;
start: string; // ISO 8601
end: string; // ISO 8601
type: string; // Flexible event type - can be any string value
allDay: boolean;
syncStatus: SyncStatus;
// Resource information (only present in resource calendar mode)
resource?: {
name: string;
displayName: string;
employeeId: string;
};
recurringId?: string;
metadata?: Record<string, any>;
}
export interface CalendarConfig {
// Scrollbar styling
scrollbarWidth: number; // Width of scrollbar in pixels
scrollbarColor: string; // Scrollbar thumb color
scrollbarTrackColor: string; // Scrollbar track color
scrollbarHoverColor: string; // Scrollbar thumb hover color
scrollbarBorderRadius: number; // Border radius for scrollbar thumb
// Interaction settings
allowDrag: boolean;
allowResize: boolean;
allowCreate: boolean;
// API settings
apiEndpoint: string;
dateFormat: string;
timeFormat: string;
// Feature flags
enableSearch: boolean;
enableTouch: boolean;
// Event defaults
defaultEventDuration: number; // Minutes
minEventDuration: number; // Minutes
maxEventDuration: number; // Minutes
}
export interface EventLogEntry {
type: string;
detail: any;
timestamp: number;
}
export interface ListenerEntry {
eventType: string;
handler: EventListener;
options?: AddEventListenerOptions;
}
export interface IEventBus {
on(eventType: string, handler: EventListener, options?: AddEventListenerOptions): () => void;
once(eventType: string, handler: EventListener): () => void;
off(eventType: string, handler: EventListener): void;
emit(eventType: string, detail?: any): boolean;
getEventLog(eventType?: string): EventLogEntry[];
setDebug(enabled: boolean): void;
destroy(): void;
}
export interface GridPosition {
minutes: number;
time: string;
y: number;
}
export interface Period {
start: string;
end: string;
mode?: CalendarMode; // Optional: which calendar mode this period is for
}
export interface EventData {
events: CalendarEvent[];
meta: {
start: string;
end: string;
total: number;
mode?: CalendarMode; // Which calendar mode this data is for
};
}
/**
* Context interfaces for different calendar modes
*/
export interface DateModeContext {
mode: 'date';
currentWeek: Date;
period: ViewPeriod;
weekDays: number;
firstDayOfWeek: number;
}
export interface ResourceModeContext {
mode: 'resource';
selectedDate: Date;
resources: Resource[];
maxResources: number;
}
/**
* Union type for type-safe mode contexts
*/
export type CalendarModeContext = DateModeContext | ResourceModeContext;