diff --git a/src/lib/stores/calendar.svelte.ts b/src/lib/stores/calendar.svelte.ts new file mode 100644 index 0000000..b4d67f7 --- /dev/null +++ b/src/lib/stores/calendar.svelte.ts @@ -0,0 +1,41 @@ +// Imported calendar events (Phase 6, FR-CAL-*). Svelte 5 runes store, same +// shape as settings.svelte.ts/meetings.svelte.ts. + +import { api, events, type CalendarEvent } from "../api"; + +class CalendarStore { + events = $state([]); + loaded = $state(false); + importing = $state(false); + importProgress = $state<{ processed: number; total: number } | null>(null); + importError = $state(null); + + async load() { + try { + this.events = await api.listCalendarEvents(); + } catch { + this.events = []; // no .pst imported yet, or command unreachable + } + if (!this.loaded) { + await events.onPstProgress((p) => (this.importProgress = p)); + this.loaded = true; + } + } + + async importPst(path: string, password?: string) { + this.importing = true; + this.importError = null; + this.importProgress = null; + try { + await api.importPst(path, password); + await this.load(); + } catch (e) { + this.importError = e instanceof Error ? e.message : String(e); + } finally { + this.importing = false; + this.importProgress = null; + } + } +} + +export const calendar = new CalendarStore();