diff --git a/assets/css/_game_list.scss b/assets/css/_game_list.scss new file mode 100644 index 0000000..6629bd1 --- /dev/null +++ b/assets/css/_game_list.scss @@ -0,0 +1,10 @@ +.player-indicator { + img { + height: 1.5em; + vertical-align: middle; + } +} + +.your-turn { + font-weight: bold; +} diff --git a/assets/css/app.scss b/assets/css/app.scss index 9b6e84e..68a0709 100644 --- a/assets/css/app.scss +++ b/assets/css/app.scss @@ -6,4 +6,6 @@ @import "layout"; @import "nav"; + +@import "game_list"; @import "board"; diff --git a/lib/chess_web/templates/game/index.html.eex b/lib/chess_web/templates/game/index.html.eex index 36be170..dbd884f 100644 --- a/lib/chess_web/templates/game/index.html.eex +++ b/lib/chess_web/templates/game/index.html.eex @@ -3,10 +3,14 @@ <%= for game <- @games do %> - + "> + diff --git a/lib/chess_web/views/game_view.ex b/lib/chess_web/views/game_view.ex index 75bf284..bf41e79 100644 --- a/lib/chess_web/views/game_view.ex +++ b/lib/chess_web/views/game_view.ex @@ -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
+ <%= link "Game with #{opponent(@conn, game).name}", to: game_path(@conn, :show, game), class: "btn btn-default btn-xs" %> + <%= if your_turn?(@conn, game) do %>Your turn<% end %> + Started on <%= Timex.format!(game.inserted_at, "%b %e at %I:%M %P", :strftime) %>