1
0
mirror of https://github.com/danbee/chess synced 2025-03-04 08:39:06 +00:00

Extract turn_class function

This commit is contained in:
Daniel Barber 2018-04-06 16:31:07 -04:00
parent 693263fb6d
commit 97a23ff9e7
Signed by: danbarber
GPG Key ID: 931D8112E0103DD8
2 changed files with 7 additions and 1 deletions

View File

@ -3,7 +3,7 @@
<table class="table">
<tbody>
<%= for game <- @games do %>
<tr class="<%= if your_turn?(@conn, game), do: "your-turn" %>">
<tr class="<%= turn_class(@conn, game) %>">
<td>
<span class="player-indicator"><img src="images/pawn_<%= player_colour(@conn, game) %>.svg"></span>
<%= link "Game with #{opponent(@conn, game).name}", to: game_path(@conn, :show, game), class: "btn btn-default btn-xs" %>

View File

@ -3,6 +3,12 @@ defmodule ChessWeb.GameView do
import Chess.Auth, only: [current_user: 1]
def turn_class(conn, game) do
if your_turn?(conn, game) do
"your-turn"
end
end
def your_turn?(conn, game) do
player_colour(conn, game) == game.turn
end