refactor: extract typed navigation routes
This commit is contained in:
@@ -80,7 +80,7 @@
|
||||
if (decoderRegistry.length > 0) callback();
|
||||
else readyCallbacks.push(callback);
|
||||
}
|
||||
function hideUnsupportedDecoderUi() {
|
||||
function applyDecoderRegistryVisibility() {
|
||||
const knownIds = new Set(decoderRegistry.map(({ id }) => id));
|
||||
const alwaysShow = /* @__PURE__ */ new Set(["overview", "rds", "sat"]);
|
||||
document.querySelectorAll(
|
||||
@@ -128,7 +128,7 @@
|
||||
readyCallbacks.splice(0).forEach((callback) => {
|
||||
callback();
|
||||
});
|
||||
hideUnsupportedDecoderUi();
|
||||
applyDecoderRegistryVisibility();
|
||||
onLoaded();
|
||||
} catch (error) {
|
||||
console.error("Failed to fetch decoder registry:", error);
|
||||
@@ -352,6 +352,44 @@
|
||||
return value;
|
||||
}
|
||||
|
||||
// src/features/navigation/routes.ts
|
||||
var TAB_ORDER = [
|
||||
"main",
|
||||
"bookmarks",
|
||||
"digital-modes",
|
||||
"map",
|
||||
"statistics",
|
||||
"recorder",
|
||||
"settings",
|
||||
"about"
|
||||
];
|
||||
var TAB_PATHS = {
|
||||
main: "/",
|
||||
bookmarks: "/bookmarks",
|
||||
"digital-modes": "/digital-modes",
|
||||
map: "/map",
|
||||
statistics: "/statistics",
|
||||
recorder: "/recorder",
|
||||
settings: "/settings",
|
||||
about: "/about"
|
||||
};
|
||||
function normalizeTabPath(pathname) {
|
||||
const raw = pathname.length > 0 ? pathname : "/";
|
||||
return raw === "/" ? "/" : raw.replace(/\/+$/, "") || "/";
|
||||
}
|
||||
function tabFromPath(pathname) {
|
||||
const normalized = normalizeTabPath(pathname);
|
||||
const match = Object.entries(TAB_PATHS).find(([, path]) => path === normalized);
|
||||
return match ? match[0] : "main";
|
||||
}
|
||||
function updateTabHistory(name, replace = false) {
|
||||
const targetPath = TAB_PATHS[name];
|
||||
if (normalizeTabPath(window.location.pathname) === targetPath) return;
|
||||
const nextUrl = `${targetPath}${window.location.search}${window.location.hash}`;
|
||||
if (replace) window.history.replaceState({}, "", nextUrl);
|
||||
else window.history.pushState({}, "", nextUrl);
|
||||
}
|
||||
|
||||
// src/app.js
|
||||
void loadDecoderRegistry(refreshOperatorLayoutCapabilities);
|
||||
var authRole = null;
|
||||
@@ -420,7 +458,7 @@
|
||||
document.querySelectorAll(".tab-bar .tab").forEach((btn) => {
|
||||
btn.classList.remove("active");
|
||||
});
|
||||
navigateToTab(tabFromPath(), { updateHistory: false, replaceHistory: true });
|
||||
navigateToTab(tabFromPath2(), { updateHistory: false, replaceHistory: true });
|
||||
syncTopBarAccess();
|
||||
}
|
||||
function showAuthError(msg) {
|
||||
@@ -4184,34 +4222,8 @@ ${unsupportedBandSummary()}`;
|
||||
});
|
||||
}
|
||||
var _activeTab = "main";
|
||||
var TAB_ORDER = ["main", "bookmarks", "digital-modes", "map", "statistics", "recorder", "settings", "about"];
|
||||
var TAB_PATHS = {
|
||||
main: "/",
|
||||
bookmarks: "/bookmarks",
|
||||
"digital-modes": "/digital-modes",
|
||||
map: "/map",
|
||||
recorder: "/recorder",
|
||||
settings: "/settings",
|
||||
about: "/about"
|
||||
};
|
||||
function normalizeTabPath(pathname) {
|
||||
const raw = typeof pathname === "string" && pathname.length > 0 ? pathname : "/";
|
||||
if (raw === "/") return "/";
|
||||
return raw.replace(/\/+$/, "") || "/";
|
||||
}
|
||||
function tabFromPath(pathname = window.location.pathname) {
|
||||
const normalized = normalizeTabPath(pathname);
|
||||
for (const [tabName, tabPath] of Object.entries(TAB_PATHS)) {
|
||||
if (normalized === tabPath) return tabName;
|
||||
}
|
||||
return "main";
|
||||
}
|
||||
function updateTabHistory(name, replaceHistory = false) {
|
||||
const targetPath = TAB_PATHS[name] || "/";
|
||||
if (normalizeTabPath(window.location.pathname) === targetPath) return;
|
||||
const nextUrl = `${targetPath}${window.location.search}${window.location.hash}`;
|
||||
const method = replaceHistory ? "replaceState" : "pushState";
|
||||
window.history[method]({}, "", nextUrl);
|
||||
function tabFromPath2(pathname = window.location.pathname) {
|
||||
return tabFromPath(pathname);
|
||||
}
|
||||
var _mapInitTimer = null;
|
||||
function _initMapWhenReady() {
|
||||
@@ -4265,7 +4277,7 @@ ${unsupportedBandSummary()}`;
|
||||
panel.appendChild(tmpl.content.cloneNode(true));
|
||||
tmpl.remove();
|
||||
panel.querySelectorAll(".sub-tab-bar").forEach(_wireSubTabBar);
|
||||
if (decoderRegistry.length) hideUnsupportedDecoderTabs();
|
||||
if (decoderRegistry.length) applyDecoderRegistryVisibility();
|
||||
}
|
||||
if (updateHistory) {
|
||||
updateTabHistory(name, replaceHistory);
|
||||
@@ -4289,7 +4301,7 @@ ${unsupportedBandSummary()}`;
|
||||
navigateToTab(btn.dataset.tab);
|
||||
});
|
||||
window.addEventListener("popstate", () => {
|
||||
navigateToTab(tabFromPath(), { updateHistory: false });
|
||||
navigateToTab(tabFromPath2(), { updateHistory: false });
|
||||
});
|
||||
(function() {
|
||||
let tx = 0, ty = 0;
|
||||
|
||||
Reference in New Issue
Block a user