ui phase 2

This commit is contained in:
hamid
2026-07-17 19:05:17 +03:30
parent 370c1beefa
commit 222856d600
42 changed files with 1354 additions and 451 deletions
+15
View File
@@ -0,0 +1,15 @@
/**
* Longest-prefix, winner-takes-all active-path matching shared by the sidebar and every bottom
* bar. Given the current (locale-stripped) pathname and a set of nav-item paths, returns the
* single path that should render as active — the longest candidate that prefixes the pathname —
* so e.g. `/nurse/requests` lights up "Requests" and not the "Dashboard" root (`/nurse`), and
* `/patients/123` still lights up the `/patients` tab.
*/
export function matchActivePath(pathname: string, paths: ReadonlyArray<string | undefined>): string | undefined {
const isMatch = (path: string) => (path === '/' ? pathname === path : pathname === path || pathname.startsWith(`${path}/`));
return paths
.filter((path): path is string => Boolean(path))
.filter(isMatch)
.sort((a, b) => b.length - a.length)[0];
}