Skip to content

Commit ae16ab2

Browse files
CopilotDevn913
andauthored
fix: address code review feedback - state flag for template, CSS variable, regex verified
Agent-Logs-Url: https://github.com/Devn913/SQL_Chess/sessions/32b36d0d-69c4-4ded-994a-17eb4abc62fa Co-authored-by: Devn913 <56478595+Devn913@users.noreply.github.com>
1 parent c75b84b commit ae16ab2

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

css/style.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ input:checked + .slider::before { transform: translateX(18px); }
766766
transition: background .15s;
767767
}
768768
.sql-move-input:focus {
769-
background: #0d1520;
769+
background: var(--bg-base);
770770
}
771771
.sql-move-input::placeholder { color: var(--text-muted); }
772772

js/app.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const state = {
4242
pendingPromotion: null, // { from, to } while waiting for user to pick
4343
capturedByWhite: [], // pieces taken by white (black pieces lost)
4444
capturedByBlack: [], // pieces taken by black (white pieces lost)
45+
sqlInputHasTemplate: false, // true while the SQL textarea shows an auto-filled template
4546
};
4647

4748
/* ─── Helpers ─────────────────────────────────────────────────── */
@@ -238,6 +239,7 @@ function fillSQLInputTemplate(sqName, piece) {
238239
`SET position = '???'\n` +
239240
`WHERE position = '${sqName}'\n` +
240241
` AND color = '${color}';`;
242+
state.sqlInputHasTemplate = true;
241243
// Place cursor on the ??? so the user can immediately type the destination
242244
const idx = input.value.indexOf('???');
243245
input.focus();
@@ -420,8 +422,9 @@ function executeMove(from, to, promotion) {
420422

421423
// Clear SQL input template after a successful board-click move
422424
const sqlMoveInput = document.getElementById('sqlMoveInput');
423-
if (sqlMoveInput && sqlMoveInput.value.includes('???')) {
425+
if (sqlMoveInput && state.sqlInputHasTemplate) {
424426
sqlMoveInput.value = '';
427+
state.sqlInputHasTemplate = false;
425428
clearSQLRunError();
426429
}
427430

@@ -787,6 +790,7 @@ function startGame(whiteName, blackName, showSQL, existingPGN) {
787790
state.capturedByWhite = [];
788791
state.capturedByBlack = [];
789792
state.pendingPromotion = null;
793+
state.sqlInputHasTemplate = false;
790794

791795
// Names in UI
792796
document.getElementById('whitePlayerName').textContent = state.whitePlayer;
@@ -1020,6 +1024,7 @@ function init() {
10201024
document.getElementById('btnClearInput').addEventListener('click', () => {
10211025
const input = document.getElementById('sqlMoveInput');
10221026
if (input) input.value = '';
1027+
state.sqlInputHasTemplate = false;
10231028
clearSQLRunError();
10241029
});
10251030
document.getElementById('sqlMoveInput').addEventListener('keydown', (e) => {

0 commit comments

Comments
 (0)