Files
faceclaw/app/native/calendar-selection.ts
T

20 lines
878 B
TypeScript

import { getStringSetting, setStringSetting } from "./settings-store";
export const CALENDAR_SELECTION_KEY = "calendar.selectedIds";
/** null means all calendars (including future ones); [] explicitly means none. */
export function readCalendarSelection(): string[] | null {
try {
const value = JSON.parse(getStringSetting(CALENDAR_SELECTION_KEY, "null"));
if (value === null) return null;
if (!Array.isArray(value) || !value.every(id => typeof id === "string" && /^\d+$/.test(id))) return null;
return Array.from(new Set<string>(value));
} catch {
return null;
}
}
export function setCalendarSelection(ids: readonly string[] | null): void {
if (ids !== null && !ids.every(id => /^\d+$/.test(id))) throw new Error("Invalid calendar ID");
setStringSetting(CALENDAR_SELECTION_KEY, JSON.stringify(ids === null ? null : Array.from(new Set(ids))));
}