defmodule ChesstrainerWeb.ChessTestLive do
use ChesstrainerWeb, :live_view
@impl true
def mount(_params, _session, socket) do
{:ok, assign(socket, last_move: "None yet", total_moves: 0)}
end
@impl true
def render(assigns) do
~H"""
Chessground LiveView Test
Last Played Move:
{@last_move}
Total Moves:
{@total_moves}
"""
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
{:noreply,
socket
|> assign(:last_move, "#{from} ➔ #{to}")
|> assign(:total_moves, socket.assigns.total_moves + 1)}
end
end