BUILD114 — исправление Agent / Mapping / Settings

This commit is contained in:
2026-08-26 11:56:32 +03:00
parent 9b4db7dc04
commit 077e9c496f
5 changed files with 210 additions and 111 deletions

View File

@@ -36,6 +36,8 @@
teamSchedule: null,
teamScheduleTournamentId: "",
settings: null,
settingsPromise: null,
settingsLoadedAt: 0,
root: null,
drawer: null,
backdrop: null,
@@ -2230,13 +2232,41 @@ document.addEventListener("visibilitychange", () => {
}
}
function loadSettingsCached({ force = false } = {}) {
const fresh = state.settings && (Date.now() - Number(state.settingsLoadedAt || 0)) < 30000;
if (!force && fresh) return Promise.resolve(state.settings);
if (state.settingsPromise) return state.settingsPromise;
state.settingsPromise = request("/api/hockey/settings", { timeoutMs: 5000 })
.then((payload) => {
state.settings = payload || {};
state.settingsLoadedAt = Date.now();
return state.settings;
})
.finally(() => { state.settingsPromise = null; });
return state.settingsPromise;
}
async function openSettings() {
let loadingModal = null;
if (!state.settings) {
loadingModal = document.createElement("div");
loadingModal.className = "hockey-settings-modal";
loadingModal.innerHTML = `
<div class="hockey-settings-backdrop"></div>
<div class="hockey-settings-card">
<header><div><small>STAT2TV</small><strong>${escapeHtml(t("settings"))}</strong></div></header>
<div class="hockey-settings-body"><p class="wide">${state.language === "en" ? "Loading settings…" : "Загрузка настроек…"}</p></div>
</div>`;
document.body.appendChild(loadingModal);
}
try {
state.settings = await request("/api/hockey/settings");
state.settings = await loadSettingsCached();
} catch (error) {
loadingModal?.remove();
notify(error.message, true);
return;
}
loadingModal?.remove();
const value = state.settings;
const modal = document.createElement("div");
@@ -2440,6 +2470,9 @@ document.addEventListener("visibilitychange", () => {
}),
});
state.settings = savedSettings || state.settings || {};
state.settingsLoadedAt = Date.now();
const username = String(values.get("username") || "").trim();
const password = String(values.get("password") || "");
if (username || password) {
@@ -2481,8 +2514,8 @@ document.addEventListener("visibilitychange", () => {
}
status.classList.remove("error");
}
await loadNavigation();
setTimeout(close, 650);
setTimeout(close, 120);
loadNavigation().catch((error) => console.warn("[Hockey] Navigation refresh after settings save failed:", error));
} catch (error) {
status.textContent = error.message;
status.classList.add("error");
@@ -2494,6 +2527,9 @@ document.addEventListener("visibilitychange", () => {
await ensureAccountScopedRuntimeState();
ensureShell();
renderStaticLabels();
// Warm the tiny local settings endpoint while navigation is loading, so the
// gear opens immediately instead of starting its first request on click.
void loadSettingsCached().catch(() => {});
await loadNavigation();
}