Files
bookhoard/web/src/storage.ts
T
John O'Keefe 77cd268f4e style: format web/src with oxfmt defaults (via vp fmt)
One-time mechanical sweep, isolated from any functional change.
- oxfmt defaults: double quotes, semicolons, 2-space indent, LF,
  printWidth 100, trailing commas, bracket spacing, arrow parens.
- vite.config.ts gains an fmt.ignorePatterns block for web/static:
  vendored/minified assets (htmx.min.js, compiled css) must never
  be reformatted.
- Verified: rebuild after the sweep produces byte-identical JS/CSS
  bundles; only sourcemaps changed (they embed sourcesContent).
2026-10-21 13:18:24 -04:00

66 lines
1.4 KiB
TypeScript

const ALL_LIBRARIES = "__all__";
function getToken(): string | null {
return localStorage.getItem("token");
}
function setToken(token: string): void {
localStorage.setItem("token", token);
}
function removeToken(): void {
localStorage.removeItem("token");
}
function getRefreshToken(): string | null {
return localStorage.getItem("refresh_token");
}
function setRefreshToken(token: string): void {
localStorage.setItem("refresh_token", token);
}
function removeRefreshToken(): void {
localStorage.removeItem("refresh_token");
}
function getTheme(): string {
return localStorage.getItem("theme") || "tokyo-night";
}
function setTheme(theme: string): void {
localStorage.setItem("theme", theme);
}
function getSelectedLibrary(): string {
const stored = localStorage.getItem("selectedLibrary");
if (stored === ALL_LIBRARIES) return "";
if (stored) return stored;
return "";
}
function setSelectedLibrary(libraryId: string): void {
const value = libraryId === "" ? ALL_LIBRARIES : libraryId;
localStorage.setItem("selectedLibrary", value);
document.cookie = `selectedLibrary=${encodeURIComponent(value)};path=/;max-age=${365 * 24 * 60 * 60};samesite=lax`;
}
function clearAll(): void {
localStorage.clear();
}
export {
ALL_LIBRARIES,
clearAll,
getRefreshToken,
getSelectedLibrary,
getTheme,
getToken,
removeRefreshToken,
removeToken,
setRefreshToken,
setSelectedLibrary,
setTheme,
setToken,
};