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

Show colour and whether it's your turn

This commit is contained in:
Daniel Barber 2018-04-06 14:21:20 -04:00
parent 35d1f33f76
commit ba70cb5f30
Signed by: danbarber
GPG Key ID: 931D8112E0103DD8
4 changed files with 28 additions and 1 deletions

View File

@ -0,0 +1,10 @@
.player-indicator {
img {
height: 1.5em;
vertical-align: middle;
}
}
.your-turn {
font-weight: bold;
}

View File

@ -6,4 +6,6 @@
@import "layout";
@import "nav";
@import "game_list";
@import "board";

View File

@ -3,10 +3,14 @@
<table class="table">
<tbody>
<%= for game <- @games do %>
<tr>
<tr class="<%= if your_turn?(@conn, game), do: "your-turn" %>">
<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" %>
</td>
<td>
<%= if your_turn?(@conn, game) do %>Your turn<% end %>
</td>
<td>
Started on <%= Timex.format!(game.inserted_at, "%b %e at %I:%M %P", :strftime) %>
</td>

View File

@ -3,6 +3,17 @@ defmodule ChessWeb.GameView do
import Chess.Auth, only: [current_user: 1]
def your_turn?(conn, game) do
player_colour(conn, game) == game.turn
end
def player_colour(conn, game) do
cond do
current_user(conn).id == game.user_id -> "white"
current_user(conn).id == game.opponent_id -> "black"
end
end
def opponent(conn, game) do
if current_user(conn).id == game.user_id do
game.opponent