aboutsummaryrefslogtreecommitdiff
path: root/packages/demobank-ui/src/hooks/index.ts
diff options
context:
space:
mode:
authorSebastian <sebasjm@gmail.com>2023-05-29 14:53:06 -0300
committerSebastian <sebasjm@gmail.com>2023-05-29 14:53:06 -0300
commitbe9d3dad83801806c9a7d99c925aa2b86571a70b (patch)
treee98c7c1810b8cc8e081b1098d0bb36a7e5a6a692 /packages/demobank-ui/src/hooks/index.ts
parentd4dd82eda110b165e62f451bb1bad65a2c9963d5 (diff)
use new local storage api
Diffstat (limited to 'packages/demobank-ui/src/hooks/index.ts')
-rw-r--r--packages/demobank-ui/src/hooks/index.ts12
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);