Record per-user Attempt history (#39)

This commit is contained in:
2026-11-03 21:50:55 +01:00
parent eea8e48685
commit a3fb878383
6 changed files with 220 additions and 0 deletions
@@ -1,6 +1,7 @@
defmodule ChesstrainerWeb.EndgameLive.Play do
use ChesstrainerWeb, :live_view
alias Chesstrainer.Attempts
alias Chesstrainer.Endgames
alias Chesstrainer.Endgames.Tablebase
@@ -657,6 +658,7 @@ defmodule ChesstrainerWeb.EndgameLive.Play do
defp solve_attempt(socket) do
{:ok, endgame} = Endgames.record_solve(socket.assigns.endgame)
record_attempt(socket, :solved)
{:noreply,
socket
@@ -667,6 +669,8 @@ defmodule ChesstrainerWeb.EndgameLive.Play do
end
defp fail_attempt(socket) do
record_attempt(socket, :failed)
{:noreply,
socket
|> assign(:status, :failed)
@@ -674,6 +678,10 @@ defmodule ChesstrainerWeb.EndgameLive.Play do
|> assign(:best_move, best_move_text(socket.assigns.tablebase))}
end
defp record_attempt(socket, outcome) do
Attempts.record_attempt(socket.assigns.current_scope, socket.assigns.endgame, outcome)
end
defp best_move_text(tablebase) do
san =
tablebase