From be9d3dad83801806c9a7d99c925aa2b86571a70b Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 29 May 2023 14:53:06 -0300 Subject: use new local storage api --- packages/demobank-ui/src/hooks/index.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'packages/demobank-ui/src/hooks/index.ts') 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 | ((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, () => 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) => { - setTriedToLog("yes"); + setTriedToLog(true); const computedValue = v instanceof Function ? v(value) : v.replace(/\/$/, ""); return setter(computedValue); -- cgit v1.2.3