taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit a6800c8a08f1a1dbff139a853848563a117977cb
parent 71c338d7660bab2172430bf187b510a3a8b515a9
Author: Sebastian <sebasjm@taler-systems.com>
Date:   Mon, 15 Dec 2025 13:09:27 -0300

rollback change in webutils

Diffstat:
Mpackages/web-util/src/context/navigation.ts | 21+++++++++++++--------
Mpackages/web-util/src/utils/route.ts | 50+++++++++++++++++++++++++-------------------------
2 files changed, 38 insertions(+), 33 deletions(-)

diff --git a/packages/web-util/src/context/navigation.ts b/packages/web-util/src/context/navigation.ts @@ -17,7 +17,12 @@ import { ComponentChildren, createContext, h, VNode } from "preact"; import { useContext, useEffect, useState } from "preact/hooks"; import { - AppLocation + AppLocation, + ObjectOf, + Location, + findMatch, + RouteDefinition, + LocationNotFound, } from "../utils/route.js"; /** @@ -38,14 +43,14 @@ const Context = createContext<Type>(undefined); export const useNavigationContext = (): Type => useContext(Context); // eslint-disable-next-line @typescript-eslint/no-explicit-any -// export function useCurrentLocation<T extends ObjectOf<RouteDefinition<any>>>( -// pagesMap: T, -// ): Location<T> | LocationNotFound<T> { -// const pageList = Object.keys(pagesMap as object) as Array<keyof T>; -// const { path, params } = useNavigationContext(); +export function useCurrentLocation<T extends ObjectOf<RouteDefinition<any>>>( + pagesMap: T, +): Location<T> | LocationNotFound<T> { + const pageList = Object.keys(pagesMap as object) as Array<keyof T>; + const { path, params } = useNavigationContext(); -// return findMatch(pagesMap, pageList, path, params); -// } + return findMatch(pagesMap, pageList, path, params); +} function getPathAndParamsFromWindow(): { path: string; diff --git a/packages/web-util/src/utils/route.ts b/packages/web-util/src/utils/route.ts @@ -76,31 +76,31 @@ export function buildNullRoutDefinition< * @param path * @param params */ -// export function findMatch<T extends ObjectOf<RouteDefinition>>( -// pagesMap: T, -// pageList: Array<keyof T>, -// path: string, -// params: Record<string, string[]>, -// ): Location<T> | LocationNotFound<T> { -// for (let idx = 0; idx < pageList.length; idx++) { -// const name = pageList[idx]; -// const found = pagesMap[name].pattern.exec(path); -// if (found !== null) { -// const values = {} as Record<string, unknown>; - -// if (found.groups !== undefined) { -// Object.entries(found.groups).forEach(([key, value]) => { -// values[key] = value; -// }); -// } - -// // @ts-expect-error values is a map string which is equivalent to the RouteParamsType -// return { name, parent: pagesMap, values, params }; -// } -// } -// // @ts-expect-error values is a map string which is equivalent to the RouteParamsType -// return { name: undefined, parent: pagesMap, values: {}, params }; -// } +export function findMatch<T extends ObjectOf<RouteDefinition>>( + pagesMap: T, + pageList: Array<keyof T>, + path: string, + params: Record<string, string[]>, +): Location<T> | LocationNotFound<T> { + for (let idx = 0; idx < pageList.length; idx++) { + const name = pageList[idx]; + const found = pagesMap[name].pattern.exec(path); + if (found !== null) { + const values = {} as Record<string, unknown>; + + if (found.groups !== undefined) { + Object.entries(found.groups).forEach(([key, value]) => { + values[key] = value; + }); + } + + // @ts-expect-error values is a map string which is equivalent to the RouteParamsType + return { name, parent: pagesMap, values, params }; + } + } + // @ts-expect-error values is a map string which is equivalent to the RouteParamsType + return { name: undefined, parent: pagesMap, values: {}, params }; +} /** * get the type of the params of a location