From 8acd9ef8d20ea3504ea44d365e71f69b29709271 Mon Sep 17 00:00:00 2001 From: Michael Pilosov Date: Thu, 25 Jun 2026 20:54:54 +0000 Subject: [PATCH] fix: saving a game with an existing name overwrites instead of duplicating saveCurrentGame always pushed a new entry, so re-saving under the same title produced two dropdown entries. Now it warns + confirms, then replaces the same-named game (case-insensitive), collapsing any existing duplicates into one. Bump asset cache version. --- src/chess_pressure/static/app.js | 12 +++++++++++- src/chess_pressure/static/index.html | 4 ++-- src/chess_pressure/static/sw.js | 2 +- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/chess_pressure/static/app.js b/src/chess_pressure/static/app.js index 5803200..ee95471 100644 --- a/src/chess_pressure/static/app.js +++ b/src/chess_pressure/static/app.js @@ -422,7 +422,17 @@ const name = (prompt("Save game as:", defaultGameName()) || "").trim(); if (!name) return; const pgn = ChessPressure.toPgn(gameData.headers, gameData.moves); - const saved = getSavedGames(); + let saved = getSavedGames(); + + // Overwrite an existing game with the same name (case-insensitive) instead of + // creating a duplicate; also collapses any pre-existing duplicates. + const key = name.toLowerCase(); + const exists = saved.some((g) => g.name.toLowerCase() === key); + if (exists) { + if (!confirm(`A game named "${name}" already exists. Overwrite it?`)) return; + saved = saved.filter((g) => g.name.toLowerCase() !== key); + } + const id = "g" + Date.now().toString(36); saved.push({ id, name, pgn, savedAt: new Date().toISOString() }); setSavedGames(saved); diff --git a/src/chess_pressure/static/index.html b/src/chess_pressure/static/index.html index ad3b558..9ba8ecb 100644 --- a/src/chess_pressure/static/index.html +++ b/src/chess_pressure/static/index.html @@ -4,7 +4,7 @@ Chess Pressure - + @@ -139,6 +139,6 @@ - + diff --git a/src/chess_pressure/static/sw.js b/src/chess_pressure/static/sw.js index f3987d9..8eecf68 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-v26"; +const CACHE = "chess-pressure-v27"; // Same-origin app shell. Cached by canonical path; the fetch handler matches // with ignoreSearch so cache-busting query strings (?v=NN) still hit.