Calendar
Access and manage calendar events.
Event Manager
The eventManager module provides access to the user's calendar events and calendars.
Usage
import { eventManager } from "@buildcosmo/widget";getCalendars()
Retrieves a list of available calendars on the device.
Usage
const calendars = await eventManager.getCalendars();
console.log("Calendars:", calendars);Returns
Promise<CalendarInfo[]>: An array of calendar objects.
CalendarInfo Type
interface CalendarInfo {
title: string;
identifier: string;
source: {
title: string;
identifier: string;
};
allowsModifications: boolean;
colorHex: string;
type: string; // e.g., "local", "calDAV", "exchange"
}getCalendarEvents(start, end)
Retrieves calendar events within a specified date range.
Usage
const start = new Date().toISOString();
const end = new Date(Date.now() + 24 * 60 * 60 * 1000).toISOString();
const events = await eventManager.getCalendarEvents(start, end);
console.log("Events:", events);Parameters
| Name | Type | Description |
|---|---|---|
start | string | The start date in ISO 8601 format. |
end | string | The end date in ISO 8601 format. |
Returns
Promise<CalendarEvent[]>: An array of event objects.
CalendarEvent Type
interface CalendarEvent {
eventId: string;
title: string;
startDate: string; // ISO string
endDate: string; // ISO string
isAllDay: boolean;
calendar: CalendarInfo;
location?: string;
notes?: string;
}registerEventChangeObserver(callback)
Registers a callback to be notified when the calendar store changes (e.g., an event is added or modified externally).
Usage
const unsubscribe = eventManager.registerEventChangeObserver(() => {
console.log("Calendar events changed. Refreshing data...");
// Re-fetch events here
});
// Later, to stop listening:
unsubscribe();Returns
() => void: A function to unregister the observer.