Add calendar store for imported events and PST import progress state
This commit is contained in:
1 parent
28225b7513
commit
6d16e6707f
1 file changed
+41
@@ -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<CalendarEvent[]>([]);
|
||||
loaded = $state(false);
|
||||
importing = $state(false);
|
||||
importProgress = $state<{ processed: number; total: number } | null>(null);
|
||||
importError = $state<string | null>(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();
|
||||
Reference in new issue
Block a user