From 791cc35962c569c35003dc1086cd0040b36852e4 Mon Sep 17 00:00:00 2001 From: Michael Pilosov Date: Thu, 25 Jun 2026 21:28:39 +0000 Subject: [PATCH] polish: route PGN-error alerts through the in-app dialog too Replaces the last native alert() calls (corrupted saved game / unparseable PGN) and the delete confirm with the same -based modalAlert/modalConfirm helpers, so no flow relies on native popups that the browser may suppress. Bump cache version. --- src/chess_pressure/static/app.js | 29 ++++++++++++++++++++++++---- src/chess_pressure/static/index.html | 6 +++--- src/chess_pressure/static/sw.js | 2 +- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/chess_pressure/static/app.js b/src/chess_pressure/static/app.js index 9318cbd..042bab0 100644 --- a/src/chess_pressure/static/app.js +++ b/src/chess_pressure/static/app.js @@ -347,7 +347,7 @@ try { parsed = ChessPressure.parsePgn(g.pgn); } catch (e) { - alert("That saved game could not be loaded (corrupted PGN)."); + modalAlert("That saved game could not be loaded (corrupted PGN).", "Couldn't load game"); return; } applyParsed(parsed, savedId, true); @@ -360,7 +360,7 @@ try { parsed = ChessPressure.parsePgn(pgn); } catch (e) { - alert("Could not parse PGN — please check the format and try again."); + modalAlert("Could not parse PGN — please check the format and try again.", "Couldn't parse PGN"); return; } applyParsed(parsed, null, isReference); @@ -458,6 +458,28 @@ }); } + // Yes/no confirmation via the in-app dialog. Resolves true (OK) / false (cancel). + function modalConfirm(message, title) { + const dlg = document.getElementById("confirm-dialog"); + document.getElementById("confirm-title").textContent = title || "Please confirm"; + document.getElementById("confirm-msg").textContent = message; + dlg.querySelector("[data-cancel]").style.display = ""; + return openModal(dlg); + } + + // Single-button notice via the in-app dialog (replaces native alert()). + function modalAlert(message, title) { + const dlg = document.getElementById("confirm-dialog"); + document.getElementById("confirm-title").textContent = title || "Notice"; + document.getElementById("confirm-msg").textContent = message; + const cancel = dlg.querySelector("[data-cancel]"); + cancel.style.display = "none"; + return openModal(dlg).then((v) => { + cancel.style.display = ""; + return v; + }); + } + async function saveCurrentGame() { if (!gameData) return; const dlg = document.getElementById("save-dialog"); @@ -502,8 +524,7 @@ if (!currentSavedId) return; const g = getSavedGames().find((x) => x.id === currentSavedId); if (!g) return; - document.getElementById("confirm-msg").textContent = `Delete saved game "${g.name}"?`; - const ok = await openModal(document.getElementById("confirm-dialog")); + const ok = await modalConfirm(`Delete saved game "${g.name}"?`, "Delete game"); if (!ok) return; setSavedGames(getSavedGames().filter((x) => x.id !== currentSavedId)); currentSavedId = null; diff --git a/src/chess_pressure/static/index.html b/src/chess_pressure/static/index.html index da52253..7ee2d2e 100644 --- a/src/chess_pressure/static/index.html +++ b/src/chess_pressure/static/index.html @@ -4,7 +4,7 @@ Chess Pressure - + @@ -137,7 +137,7 @@
-

Please confirm

+

Please confirm

@@ -164,6 +164,6 @@ - + diff --git a/src/chess_pressure/static/sw.js b/src/chess_pressure/static/sw.js index a8f8b96..15528fb 100644 --- a/src/chess_pressure/static/sw.js +++ b/src/chess_pressure/static/sw.js @@ -7,7 +7,7 @@ * * Bump CACHE on every deploy so clients pick up new assets. */ -const CACHE = "chess-pressure-v29"; +const CACHE = "chess-pressure-v30"; // Same-origin app shell. Cached by canonical path; the fetch handler matches // with ignoreSearch so cache-busting query strings (?v=NN) still hit.