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 <dialog>-based modalAlert/modalConfirm
helpers, so no flow relies on native popups that the browser may suppress.
Bump cache version.
This commit is contained in:
Michael Pilosov 2026-06-25 21:28:39 +00:00
parent 233ecb97c0
commit 791cc35962
3 changed files with 29 additions and 8 deletions

View File

@ -347,7 +347,7 @@
try { try {
parsed = ChessPressure.parsePgn(g.pgn); parsed = ChessPressure.parsePgn(g.pgn);
} catch (e) { } 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; return;
} }
applyParsed(parsed, savedId, true); applyParsed(parsed, savedId, true);
@ -360,7 +360,7 @@
try { try {
parsed = ChessPressure.parsePgn(pgn); parsed = ChessPressure.parsePgn(pgn);
} catch (e) { } 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; return;
} }
applyParsed(parsed, null, isReference); 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() { async function saveCurrentGame() {
if (!gameData) return; if (!gameData) return;
const dlg = document.getElementById("save-dialog"); const dlg = document.getElementById("save-dialog");
@ -502,8 +524,7 @@
if (!currentSavedId) return; if (!currentSavedId) return;
const g = getSavedGames().find((x) => x.id === currentSavedId); const g = getSavedGames().find((x) => x.id === currentSavedId);
if (!g) return; if (!g) return;
document.getElementById("confirm-msg").textContent = `Delete saved game "${g.name}"?`; const ok = await modalConfirm(`Delete saved game "${g.name}"?`, "Delete game");
const ok = await openModal(document.getElementById("confirm-dialog"));
if (!ok) return; if (!ok) return;
setSavedGames(getSavedGames().filter((x) => x.id !== currentSavedId)); setSavedGames(getSavedGames().filter((x) => x.id !== currentSavedId));
currentSavedId = null; currentSavedId = null;

View File

@ -4,7 +4,7 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chess Pressure</title> <title>Chess Pressure</title>
<link rel="stylesheet" href="/style.css?v=29"> <link rel="stylesheet" href="/style.css?v=30">
<link rel="stylesheet" href="https://unpkg.com/@chrisoakman/chessboardjs@1.0.0/dist/chessboard-1.0.0.min.css"> <link rel="stylesheet" href="https://unpkg.com/@chrisoakman/chessboardjs@1.0.0/dist/chessboard-1.0.0.min.css">
<link rel="manifest" href="/manifest.json"> <link rel="manifest" href="/manifest.json">
</head> </head>
@ -137,7 +137,7 @@
<dialog id="confirm-dialog"> <dialog id="confirm-dialog">
<form method="dialog"> <form method="dialog">
<h2>Please confirm</h2> <h2 id="confirm-title">Please confirm</h2>
<p id="confirm-msg" class="export-info"></p> <p id="confirm-msg" class="export-info"></p>
<div class="dialog-buttons"> <div class="dialog-buttons">
<button type="button" data-ok>OK</button> <button type="button" data-ok>OK</button>
@ -164,6 +164,6 @@
<script src="/chess.min.js"></script> <script src="/chess.min.js"></script>
<script src="/gif.js"></script> <script src="/gif.js"></script>
<script src="/engine.js"></script> <script src="/engine.js"></script>
<script src="/app.js?v=29"></script> <script src="/app.js?v=30"></script>
</body> </body>
</html> </html>

View File

@ -7,7 +7,7 @@
* *
* Bump CACHE on every deploy so clients pick up new assets. * 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 // Same-origin app shell. Cached by canonical path; the fetch handler matches
// with ignoreSearch so cache-busting query strings (?v=NN) still hit. // with ignoreSearch so cache-busting query strings (?v=NN) still hit.