diff options
| author | Christian Cleberg <[email protected]> | 2026-04-18 22:32:53 -0500 |
|---|---|---|
| committer | Christian Cleberg <[email protected]> | 2026-04-18 22:32:53 -0500 |
| commit | 580e798e16346eb894eb899edac82d2efdf40adc (patch) | |
| tree | 6dec3b7db678f781138b40d34da37d21ac8fbe7d /src/hooks/useSettings.ts | |
| download | brand-bench-580e798e16346eb894eb899edac82d2efdf40adc.tar.gz brand-bench-580e798e16346eb894eb899edac82d2efdf40adc.tar.bz2 brand-bench-580e798e16346eb894eb899edac82d2efdf40adc.zip | |
initial commit
Diffstat (limited to 'src/hooks/useSettings.ts')
| -rw-r--r-- | src/hooks/useSettings.ts | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/hooks/useSettings.ts b/src/hooks/useSettings.ts new file mode 100644 index 0000000..2452945 --- /dev/null +++ b/src/hooks/useSettings.ts @@ -0,0 +1,41 @@ +import { useState } from 'react'; + +export interface OllamaSettings { + enabled: boolean; + baseUrl: string; + model: string; +} + +const DEFAULTS: OllamaSettings = { + enabled: false, + baseUrl: 'http://localhost:11434', + model: 'llama3.2', +}; + +const KEY = 'bw:settings'; + +function load(): OllamaSettings { + try { + const raw = localStorage.getItem(KEY); + return raw ? { ...DEFAULTS, ...JSON.parse(raw) } : { ...DEFAULTS }; + } catch { + return { ...DEFAULTS }; + } +} + +// Non-reactive read — used inside callbacks without needing the hook +export function readSettings(): OllamaSettings { + return load(); +} + +export function useSettings() { + const [settings, setSettingsRaw] = useState<OllamaSettings>(load); + + const setSettings = (next: Partial<OllamaSettings>) => { + const merged = { ...settings, ...next }; + try { localStorage.setItem(KEY, JSON.stringify(merged)); } catch { /* ignore */ } + setSettingsRaw(merged); + }; + + return { settings, setSettings }; +} |
