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 {
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;

View File

@ -4,7 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<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="manifest" href="/manifest.json">
</head>
@ -137,7 +137,7 @@
<dialog id="confirm-dialog">
<form method="dialog">
<h2>Please confirm</h2>
<h2 id="confirm-title">Please confirm</h2>
<p id="confirm-msg" class="export-info"></p>
<div class="dialog-buttons">
<button type="button" data-ok>OK</button>
@ -164,6 +164,6 @@
<script src="/chess.min.js"></script>
<script src="/gif.js"></script>
<script src="/engine.js"></script>
<script src="/app.js?v=29"></script>
<script src="/app.js?v=30"></script>
</body>
</html>

View File

@ -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.