Fix back button closing modal

This commit is contained in:
Your Name 2025-12-26 02:27:39 -05:00
parent 8adab752ff
commit f6cda99b4c
1 changed files with 7 additions and 3 deletions

View File

@ -323,12 +323,13 @@ function normalizeImageUrl(raw) {
return value;
}
function closeCenteredOverlay(map) {
function closeCenteredOverlay(map, opts = {}) {
try {
const ov = map?.__swCenteredOverlay;
if (!ov) return;
if (ov.closing) return;
ov.closing = true;
const skipHistory = !!opts.skipHistory;
if (ov.onKey) window.removeEventListener("keydown", ov.onKey);
if (ov.onAuth) window.removeEventListener("sociowire:auth-changed", ov.onAuth);
@ -352,7 +353,7 @@ function closeCenteredOverlay(map) {
map.__swCenteredOverlay = null;
if (ov.historyPushed && !ov.historyClosed) {
if (!skipHistory && ov.historyPushed && !ov.historyClosed) {
ov.historyClosed = true;
try { window.history.back(); } catch {}
}
@ -535,7 +536,10 @@ export function openCenteredOverlay({ map, post, theme, fullScreen = false }) {
}
onPop = () => {
const ov = map.__swCenteredOverlay;
if (ov && ov.postId === postID) closeCenteredOverlay(map);
if (ov && ov.postId === postID) {
ov.historyClosed = true;
closeCenteredOverlay(map, { skipHistory: true });
}
};
window.addEventListener("popstate", onPop);
} catch {}