Skip to content

Commit 11f0010

Browse files
CopilotDevn913
andauthored
fix: extract SAMPLE_SQL_QUERY constant, correct sqlInputHasTemplate flags, add auto-scroll for atEnd blocks
Agent-Logs-Url: https://github.com/Devn913/SQL_Chess/sessions/d99e2bd3-f90d-47a3-9be1-466c214ff74b Co-authored-by: Devn913 <56478595+Devn913@users.noreply.github.com>
1 parent 0fe878f commit 11f0010

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

js/app.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
'use strict';
1717

1818
/* ─── Configuration ──────────────────────────────────────────── */
19+
const SAMPLE_SQL_QUERY =
20+
`-- Sample: move the e-pawn two squares forward\nUPDATE chess_piece\nSET position = 'e4'\nWHERE position = 'e2';`;
21+
1922
const PIECE_UNICODE = {
2023
wK: '♔', wQ: '♕', wR: '♖', wB: '♗', wN: '♘', wP: '♙',
2124
bK: '♚', bQ: '♛', bR: '♜', bB: '♝', bN: '♞', bP: '♟',
@@ -833,8 +836,11 @@ function appendSQL(code, label, moveNum, atEnd) {
833836
state.sqlBlocks.push({ code, label, moveNum });
834837

835838
if (document.getElementById('chkAutoScroll').checked) {
836-
// Scroll to top to reveal the freshly-prepended block
837-
if (!atEnd) {
839+
if (atEnd) {
840+
// Game-init block appended at bottom — scroll down to show it
841+
content.scrollTop = content.scrollHeight;
842+
} else {
843+
// Move blocks prepended at top — scroll up to reveal the new block
838844
content.scrollTop = 0;
839845
}
840846
}
@@ -864,10 +870,9 @@ function startGame(whiteName, blackName, showSQL, existingPGN) {
864870
// Clear SQL input and pre-fill with sample query
865871
const sqlMoveInput = document.getElementById('sqlMoveInput');
866872
if (sqlMoveInput) {
867-
sqlMoveInput.value =
868-
`-- Sample: move the e-pawn two squares forward\nUPDATE chess_piece\nSET position = 'e4'\nWHERE position = 'e2';`;
873+
sqlMoveInput.value = SAMPLE_SQL_QUERY;
869874
}
870-
state.sqlInputHasTemplate = false;
875+
state.sqlInputHasTemplate = true;
871876
clearSQLRunError();
872877

873878
// SQL panel visibility
@@ -1093,10 +1098,9 @@ function init() {
10931098
document.getElementById('btnSampleSQL').addEventListener('click', () => {
10941099
const input = document.getElementById('sqlMoveInput');
10951100
if (input) {
1096-
input.value =
1097-
`-- Sample: move the e-pawn two squares forward\nUPDATE chess_piece\nSET position = 'e4'\nWHERE position = 'e2';`;
1101+
input.value = SAMPLE_SQL_QUERY;
10981102
}
1099-
state.sqlInputHasTemplate = false;
1103+
state.sqlInputHasTemplate = true;
11001104
clearSQLRunError();
11011105
});
11021106
document.getElementById('btnClearInput').addEventListener('click', () => {

0 commit comments

Comments
 (0)