From a032af3b0009b6d70ff3222bc2865dcce29ca633 Mon Sep 17 00:00:00 2001 From: 4aiman Date: Wed, 27 May 2026 19:36:34 +0300 Subject: [PATCH] Fix map fullscreen state sync, closeModal flag, remove duplicate code Map fullscreen: - Removed mapIsFullscreen variable, use CSS class as single source of truth - popHandler and toggleMapFs now both check mapEl.classList - After back-gesture collapse, expand button works on first click (not second) closeModal: - Sets _modalPopHandled flag before history.back() - Prevents global popstate handler from double-processing the event - Fixes: back from modal no longer closes the app Removed duplicate fsChart block (caused SyntaxError) --- frontend/js/main.js | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/frontend/js/main.js b/frontend/js/main.js index f3d7599..82bff91 100644 --- a/frontend/js/main.js +++ b/frontend/js/main.js @@ -814,8 +814,10 @@ function showModal(html, onSubmit) { const fsMap = overlay.querySelector(".sd-map-full"); if (fsMap) { fsMap.classList.remove("sd-map-full"); + // Update expand button icon const expandBtn = fsMap.querySelector(".sd-map-expand-btn"); if (expandBtn) expandBtn.innerHTML = "⛶"; + // Reset map controls and size try { const mapObj = fsMap._leafletMap; if (mapObj) { @@ -828,6 +830,7 @@ function showModal(html, onSubmit) { }, 100); } } catch {} + // Stay in modal — re-push entry that back consumed history.pushState({ modal: true }, ""); return; } @@ -848,6 +851,7 @@ function showModal(html, onSubmit) { window.addEventListener("popstate", popHandler); function closeModal() { + _modalPopHandled = true; // prevent global handler from also processing the back window.removeEventListener("popstate", popHandler); overlay.remove(); history.back(); // pops {modal: true}, returns to previous screen @@ -2600,27 +2604,20 @@ async function showSessionDetail(sessionId) { // Fullscreen toggle button on map // Fullscreen map toggle - let mapIsFullscreen = false; - - function collapseMap() { - if (!mapIsFullscreen) return; - mapIsFullscreen = false; - mapEl.classList.remove("sd-map-full"); - fsDiv.innerHTML = "⛶"; - setTimeout(() => { map.invalidateSize(); map.fitBounds(L.latLngBounds(allCoords).pad(0.05)); }, 100); - } - function toggleMapFs() { - if (mapIsFullscreen) { - collapseMap(); + if (mapEl.classList.contains("sd-map-full")) { + // Collapse + mapEl.classList.remove("sd-map-full"); + fsDiv.innerHTML = "⛶"; map.dragging.disable(); map.scrollWheelZoom.disable(); + setTimeout(() => { map.invalidateSize(); map.fitBounds(L.latLngBounds(allCoords).pad(0.05)); }, 100); } else { - mapIsFullscreen = true; + // Expand mapEl.classList.add("sd-map-full"); fsDiv.innerHTML = "✕"; map.dragging.enable(); - map.scrollWheelZoom.enable(); // zoom without ctrl in fullscreen + map.scrollWheelZoom.enable(); setTimeout(() => { map.invalidateSize(); map.fitBounds(L.latLngBounds(allCoords).pad(0.05)); }, 100); } }