feat(ui): abort-game button next to new-game

Shows only while a game is in progress (hidden otherwise), red-tinted
to distinguish from new-game. Hits POST /api/abort-game after a small
confirm prompt. Game-over event hides it again.
This commit is contained in:
ai-chess
2026-05-15 00:46:53 +03:00
parent 37bac9b0f6
commit e7c04a3d76
3 changed files with 21 additions and 9 deletions
+18 -9
View File
@@ -349,16 +349,20 @@ function isGameInProgress() {
function refreshGamesLink() {
const link = $("games-link");
if (!link) return;
if (isGameInProgress()) {
link.classList.add("disabled");
link.title = "finish or abort the current game to open games & stats";
link.removeAttribute("href");
} else {
link.classList.remove("disabled");
link.removeAttribute("title");
link.setAttribute("href", "/games");
const abortBtn = $("abort-game");
const inProgress = isGameInProgress();
if (link) {
if (inProgress) {
link.classList.add("disabled");
link.title = "finish or abort the current game to open games & stats";
link.removeAttribute("href");
} else {
link.classList.remove("disabled");
link.removeAttribute("title");
link.setAttribute("href", "/games");
}
}
if (abortBtn) abortBtn.hidden = !inProgress;
}
function refreshSetupGate() {
@@ -405,6 +409,11 @@ document.addEventListener("click", (e) => {
$("new-game").addEventListener("click", () => openSetupDialog());
$("abort-game").addEventListener("click", async () => {
if (!confirm("Прервать текущую партию?")) return;
await fetch("/api/abort-game", { method: "POST" });
});
// Agent change → repopulate models
for (const side of ["white", "black"]) {
document.querySelector(`[name="${side}-agent"]`).addEventListener("change", () => {