mirror of
https://github.com/TheRealOwenRees/chess-endgame-trainer.git
synced 2026-11-18 03:32:06 +00:00
- /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
28 lines
788 B
JavaScript
28 lines
788 B
JavaScript
// 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}`;
|
|
},
|
|
};
|