Skip to main content
Glama
deleonio
by deleonio
store.ts1.7 kB
import { Option } from '@public-ui/components'; import PackageJson from '@public-ui/components/package.json'; import { isTheme, Store, THEME_OPTIONS, ThemeAndUnstyled } from './theme'; const STORE_IDENTIFIER = `public-ui.v${PackageJson.version}`; class StaticStorage { private readonly store: Map<string, string> = new Map(); public setItem(key: string, value: string) { this.store.set(key, value); } public getItem(key: string) { return this.store.get(key) || null; } } const STORE: Store = { darkMode: false, theme: 'default', }; let STORAGE: Storage; export function setStorage(storage: Storage) { STORAGE = storage; const RESTORE = STORAGE.getItem(STORE_IDENTIFIER); try { const store = JSON.parse(RESTORE as string) as Store; if (typeof store === 'object' && store !== null) { STORE.darkMode = store.darkMode === true; if (isTheme(store.theme)) { STORE.theme = store.theme; } } } catch (e) { /* empty */ } } setStorage(new StaticStorage() as unknown as Storage); const setStore = () => { STORAGE.setItem(STORE_IDENTIFIER, JSON.stringify(STORE)); }; export const setTheme = (theme: ThemeAndUnstyled) => { if (isTheme(theme)) { STORE.theme = theme; setStore(); } else { throw new Error(`The theme identifier "${theme}" is not valid or an available option.`); } }; export const getTheme = (): ThemeAndUnstyled => { return `${STORE.theme}`; }; export const getThemeName = (theme: ThemeAndUnstyled) => { if (isTheme(theme)) { return THEME_OPTIONS.find((option) => (option as Option<ThemeAndUnstyled>).value === theme)?.label; } else { throw new Error(`The theme identifier "${theme}" is not valid or an available option.`); } };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/deleonio/public-ui-kolibri'

If you have feedback or need assistance with the MCP directory API, please join our Discord server