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)
This commit is contained in:
4aiman 2026-05-27 19:36:34 +03:00
commit a032af3b00

View file

@ -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);
}
}