Replace the FastAPI/HTMX prototype with a Node/Hono session proxy and a React 19/Vite SPA. Mail (conversation view, search operators, labels, sanitised HTML, privacy image proxy, invites, undo send, templates), calendar (month/week/day/agenda, invites, free/busy, categories, context menus), contacts (JSContact, groups, vCard), files, Sieve filter builder (incl. filter-from-message with retroactive apply), vacation, identities with default + Reply-To, PWA/mobile layout, push via SSE, in-memory mock Stalwart for dev, Docker + CI.
43 lines
1.0 KiB
TypeScript
43 lines
1.0 KiB
TypeScript
const PREFIX = "ihasmail:";
|
|
|
|
export function loadJson<T>(key: string, fallback: T): T {
|
|
try {
|
|
const raw = localStorage.getItem(PREFIX + key);
|
|
if (raw == null) return fallback;
|
|
return { ...fallback, ...(JSON.parse(raw) as T) };
|
|
} catch {
|
|
return fallback;
|
|
}
|
|
}
|
|
|
|
export function loadRaw<T>(key: string, fallback: T): T {
|
|
try {
|
|
const raw = localStorage.getItem(PREFIX + key);
|
|
if (raw == null) return fallback;
|
|
return JSON.parse(raw) as T;
|
|
} catch {
|
|
return fallback;
|
|
}
|
|
}
|
|
|
|
export function saveJson(key: string, value: unknown): void {
|
|
try {
|
|
localStorage.setItem(PREFIX + key, JSON.stringify(value));
|
|
} catch {
|
|
/* quota exceeded or private mode */
|
|
}
|
|
}
|
|
|
|
export function removeKey(key: string): void {
|
|
try {
|
|
localStorage.removeItem(PREFIX + key);
|
|
} catch {
|
|
/* ignore */
|
|
}
|
|
}
|
|
|
|
/** Namespaced per account so multiple logins on one browser don't collide. */
|
|
export function accountKey(accountId: string | null | undefined, key: string): string {
|
|
return `${accountId ?? "anon"}:${key}`;
|
|
}
|