commit 633cebb5adfc15ad00b8e39b1eb787f979fc79f4
parent 6f1e8504ac78bb2d47d5cb7a9f046151c1d383d5
Author: Florian Dold <dold@taler.net>
Date: Mon, 31 Aug 2026 19:14:31 +0200
auditor web UI: use Tailwind and Wouter
Diffstat:
2 files changed, 34 insertions(+), 35 deletions(-)
diff --git a/packages/taler-auditor-webui/src/routing/useHashLocation.test.ts b/packages/taler-auditor-webui/src/routing/useHashLocation.test.ts
@@ -0,0 +1,28 @@
+/*
+ This file is part of GNU Taler
+ (C) 2026 Taler Systems S.A.
+
+ GNU Taler is free software; you can redistribute it and/or modify it under the
+ terms of the GNU General Public License as published by the Free Software
+ Foundation; either version 3, or (at your option) any later version.
+
+ GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
+ A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License along with
+ GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+import assert from "node:assert";
+import test from "node:test";
+import { auditorRoutePath } from "./useHashLocation.js";
+
+test("derive the route path from a hash location", () => {
+ assert.equal(auditorRoutePath("/"), "/");
+ assert.equal(auditorRoutePath("/key-figures"), "/key-figures");
+ assert.equal(
+ auditorRoutePath("/amount-arithmetic-inconsistencies?limit=20"),
+ "/amount-arithmetic-inconsistencies",
+ );
+});
diff --git a/packages/taler-auditor-webui/src/routing/useHashLocation.ts b/packages/taler-auditor-webui/src/routing/useHashLocation.ts
@@ -7,42 +7,13 @@
Foundation; either version 3, or (at your option) any later version.
*/
-import { useEffect, useState } from "preact/hooks";
+import { useHashLocation as useWouterHashLocation } from "wouter-preact/use-hash-location";
-function currentPathname(): string {
- const hash = window.location.hash;
- if (!hash || hash === "#") return "/";
- const path = hash.slice(1).split("?")[0] ?? "/";
- return path.startsWith("/") ? path : `/${path}`;
+export function auditorRoutePath(location: string): string {
+ return location.split("?", 1)[0] || "/";
}
-export function useHashLocation(): [
- string,
- (to: string, options?: { replace?: boolean }) => void,
-] {
- const [location, setLocation] = useState(currentPathname);
-
- useEffect(() => {
- const update = (): void => setLocation(currentPathname());
- window.addEventListener("hashchange", update);
- window.addEventListener("popstate", update);
- return () => {
- window.removeEventListener("hashchange", update);
- window.removeEventListener("popstate", update);
- };
- }, []);
-
- const navigate = (to: string, options?: { replace?: boolean }): void => {
- const path = to.startsWith("#") ? to.slice(1) : to;
- const hash = path.startsWith("/") ? `#${path}` : `#/${path}`;
- if (window.location.hash === hash) return;
- if (options?.replace) {
- history.replaceState(null, "", hash);
- window.dispatchEvent(new HashChangeEvent("hashchange"));
- } else {
- window.location.hash = hash;
- }
- };
-
- return [location, navigate];
+export function useHashLocation(): ReturnType<typeof useWouterHashLocation> {
+ const [location, navigate] = useWouterHashLocation();
+ return [auditorRoutePath(location), navigate];
}