return SAN notation of last move
This commit is contained in:
@@ -3,7 +3,7 @@ defmodule ChesstrainerWeb.ChessTestLive do
|
||||
|
||||
@impl true
|
||||
def mount(_params, _session, socket) do
|
||||
{:ok, assign(socket, last_move: "None yet", total_moves: 0)}
|
||||
{:ok, assign(socket, last_move: "None yet", total_moves: 0, san: "None yet")}
|
||||
end
|
||||
|
||||
@impl true
|
||||
@@ -16,6 +16,7 @@ defmodule ChesstrainerWeb.ChessTestLive do
|
||||
<div>
|
||||
<p class="text-sm text-gray-600 font-semibold">Last Played Move:</p>
|
||||
<p class="text-lg font-mono text-blue-600">{@last_move}</p>
|
||||
<p class="text-lg font-mono text-blue-600">{@san}</p>
|
||||
</div>
|
||||
<div>
|
||||
<p class="text-sm text-gray-600 font-semibold">Total Moves:</p>
|
||||
@@ -37,11 +38,15 @@ defmodule ChesstrainerWeb.ChessTestLive do
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_event("move_played", %{"from" => from, "to" => to, "fen" => _fen}, socket) do
|
||||
# Receive the payload sent from the client JS Hook via this.pushEvent
|
||||
def handle_event(
|
||||
"move_played",
|
||||
%{"from" => from, "to" => to, "fen" => _fen, "san" => san},
|
||||
socket
|
||||
) do
|
||||
{:noreply,
|
||||
socket
|
||||
|> assign(:last_move, "#{from} ➔ #{to}")
|
||||
|> assign(:san, san)
|
||||
|> assign(:total_moves, socket.assigns.total_moves + 1)}
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user