mirror of
https://github.com/TheRealOwenRees/chess-endgame-trainer.git
synced 2026-11-18 11:42:07 +00:00
Record per-user Attempt history (#39)
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user