add puzzle training sessions with difficulty and ratings

- /train starts an ephemeral session by choosing easy/medium/hard, banded
  relative to the user's current rating (band width configurable)
- session timer, average per-puzzle time, net rating gain and per-puzzle delta
- next puzzle, plus review and retry reused from the play surface
- explicit stop/start: stopping returns to the difficulty picker
- puzzle rating shown once a puzzle completes, and a side-to-move indicator
- extract the play logic/markup into shared PlayCore and PlayComponents so the
  standalone play view and sessions share one implementation
- sticky footer; glossary entries for Difficulty and Session; ADR 0009
This commit is contained in:
2026-11-05 15:44:11 +01:00
parent c95173cda8
commit 55d2e2a913
19 changed files with 1705 additions and 766 deletions
+5 -1
View File
@@ -6,6 +6,10 @@
html { scroll-behavior: smooth; }
body {
min-width: 320px;
min-height: 100vh;
min-height: 100dvh;
display: flex;
flex-direction: column;
background: var(--color-canvas);
color: var(--color-body);
font-family: 'DM Sans', sans-serif;
@@ -14,7 +18,7 @@
button { cursor: pointer; }
}
main { overflow: hidden; }
main { overflow: hidden; flex: 1 0 auto; }
/* LiveView */
@custom-variant phx-click-loading (.phx-click-loading&, .phx-click-loading &);
+2
View File
@@ -28,11 +28,13 @@ import { hooks as colocatedHooks } from "phoenix-colocated/chesstrainer";
import topbar from "../vendor/topbar";
import { ChessBoard } from "./hooks/chessBoard";
import { CopyFen } from "./hooks/copyFen";
import { SessionClock } from "./hooks/sessionClock";
let Hooks = {
...colocatedHooks,
ChessBoard,
CopyFen,
SessionClock,
};
const csrfToken = document.querySelector("meta[name='csrf-token']").getAttribute("content");
+27
View File
@@ -0,0 +1,27 @@
// Ticks a session clock in mm:ss from its `data-started-at` (unix ms) so the
// timer advances without a server round-trip. The server renders the initial
// value, so a re-render stays in sync with the client.
export const SessionClock = {
mounted() {
this.tick();
this.timer = setInterval(() => this.tick(), 1000);
},
updated() {
this.tick();
},
destroyed() {
clearInterval(this.timer);
},
tick() {
const startedAt = parseInt(this.el.dataset.startedAt, 10);
if (!startedAt) return;
const total = Math.max(0, Math.floor((Date.now() - startedAt) / 1000));
const minutes = String(Math.floor(total / 60)).padStart(2, "0");
const seconds = String(total % 60).padStart(2, "0");
this.el.textContent = `${minutes}:${seconds}`;
},
};