From 98f423b79410e0ffdba40141a68a2f57b2ac9a26 Mon Sep 17 00:00:00 2001 From: Michael Pilosov Date: Thu, 25 Jun 2026 22:02:38 +0000 Subject: [PATCH] feat: set White/Black names in the Save dialog too Mirrors the Export PGN dialog: Save now has White/Black fields (pre-filled, placeholders blank) and writes the names back to headers + on-screen info, so a saved game stores real player names instead of You/Opponent. Shared prefill/ write-back helpers between the two dialogs. Bump cache version. --- src/chess_pressure/static/app.js | 32 ++++++++++++++++++++-------- src/chess_pressure/static/index.html | 6 ++++-- src/chess_pressure/static/sw.js | 2 +- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/chess_pressure/static/app.js b/src/chess_pressure/static/app.js index f806300..f3e390f 100644 --- a/src/chess_pressure/static/app.js +++ b/src/chess_pressure/static/app.js @@ -423,6 +423,21 @@ return g ? g.name : null; } + // Player-name fields shared by the Save and Export dialogs. Pre-fill treats + // PGN placeholders ("?") as blank; write-back updates headers + on-screen info. + const cleanHeader = (v) => (v && v !== "?" && v !== "????.??.??" ? v : ""); + + function prefillPlayerInputs(whiteEl, blackEl) { + whiteEl.value = cleanHeader(gameData.headers.White); + blackEl.value = cleanHeader(gameData.headers.Black); + } + + function applyPlayerInputs(whiteEl, blackEl) { + gameData.headers.White = whiteEl.value.trim() || "White"; + gameData.headers.Black = blackEl.value.trim() || "Black"; + updateGameInfo(); + } + // Promise-based in-app modal. Native prompt()/confirm() are unreliable here — // browsers suppress them when the page isn't the active tab — so all save/delete // prompts go through a real . Resolves to true (OK) or false (cancel/Esc). @@ -485,7 +500,10 @@ const dlg = document.getElementById("save-dialog"); const input = document.getElementById("save-name"); const note = document.getElementById("save-note"); + const whiteEl = document.getElementById("save-white"); + const blackEl = document.getElementById("save-black"); input.value = currentSavedName() || defaultGameName(); + prefillPlayerInputs(whiteEl, blackEl); // Live "this overwrites" warning, so clicking Save IS the confirmation. const refreshNote = () => { @@ -504,6 +522,8 @@ const name = input.value.trim(); if (!name) return; + applyPlayerInputs(whiteEl, blackEl); + // Replace any same-named game (case-insensitive); also collapses old duplicates. const key = name.toLowerCase(); const saved = getSavedGames().filter((g) => g.name.toLowerCase() !== key); @@ -535,22 +555,16 @@ async function exportPGN() { if (!gameData) return; - // Let the user set player names before download; pre-fill from headers, - // treating placeholders ("?") as blank. Names are written back so they show - // on screen and persist on Save too. + // Let the user set player names before download (shared with the Save dialog). const whiteEl = document.getElementById("pgn-white"); const blackEl = document.getElementById("pgn-black"); - const real = (v) => (v && v !== "?" && v !== "????.??.??" ? v : ""); - whiteEl.value = real(gameData.headers.White); - blackEl.value = real(gameData.headers.Black); + prefillPlayerInputs(whiteEl, blackEl); setTimeout(() => { whiteEl.focus(); whiteEl.select(); }, 0); const ok = await openModal(document.getElementById("export-pgn-dialog")); if (!ok) return; - gameData.headers.White = whiteEl.value.trim() || "White"; - gameData.headers.Black = blackEl.value.trim() || "Black"; - updateGameInfo(); + applyPlayerInputs(whiteEl, blackEl); const pgn = ChessPressure.toPgn(gameData.headers, gameData.moves); const slug = (defaultGameName() || "game") diff --git a/src/chess_pressure/static/index.html b/src/chess_pressure/static/index.html index bc58541..41bfcf8 100644 --- a/src/chess_pressure/static/index.html +++ b/src/chess_pressure/static/index.html @@ -4,7 +4,7 @@ Chess Pressure - + @@ -127,6 +127,8 @@ + +
@@ -176,6 +178,6 @@ - + diff --git a/src/chess_pressure/static/sw.js b/src/chess_pressure/static/sw.js index 7c93399..70d3413 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-v31"; +const CACHE = "chess-pressure-v32"; // Same-origin app shell. Cached by canonical path; the fetch handler matches // with ignoreSearch so cache-busting query strings (?v=NN) still hit.