diff options
Diffstat (limited to 'packages/demobank-ui/src/hooks/index.ts')
-rw-r--r-- | packages/demobank-ui/src/hooks/index.ts | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/packages/demobank-ui/src/hooks/index.ts b/packages/demobank-ui/src/hooks/index.ts index 44b0598e6..e9c68812c 100644 --- a/packages/demobank-ui/src/hooks/index.ts +++ b/packages/demobank-ui/src/hooks/index.ts @@ -20,7 +20,8 @@ */ import { StateUpdater } from "preact/hooks"; -import { useLocalStorage } from "@gnu-taler/web-util/browser"; +import { buildStorageKey, useLocalStorage } from "@gnu-taler/web-util/browser"; +import { codecForBoolean } from "@gnu-taler/taler-util"; export type ValueOrFunction<T> = T | ((p: T) => T); const calculateRootPath = () => { @@ -31,11 +32,14 @@ const calculateRootPath = () => { return rootPath; }; +const BACKEND_URL_KEY = buildStorageKey("backend-url"); +const TRIED_LOGIN_KEY = buildStorageKey("tried-login", codecForBoolean()); + export function useBackendURL( url?: string, ): [string, boolean, StateUpdater<string>, () => void] { const { value, update: setter } = useLocalStorage( - "backend-url", + BACKEND_URL_KEY, url || calculateRootPath(), ); @@ -43,10 +47,10 @@ export function useBackendURL( value: triedToLog, update: setTriedToLog, reset: resetBackend, - } = useLocalStorage("tried-login"); + } = useLocalStorage(TRIED_LOGIN_KEY); const checkedSetter = (v: ValueOrFunction<string>) => { - setTriedToLog("yes"); + setTriedToLog(true); const computedValue = v instanceof Function ? v(value) : v.replace(/\/$/, ""); return setter(computedValue); |