Skip to content

Commit

Permalink
Merge pull request #107 from lazycoder9/fix/crash_creating_game
Browse files Browse the repository at this point in the history
fix crash while creating game
  • Loading branch information
imamatory committed Aug 14, 2017
2 parents af8fb7f + 1d8dd50 commit e0aaa65
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/codebattle/play/supervisor.ex
Expand Up @@ -22,7 +22,7 @@ defmodule Play.Supervisor do
__MODULE__
|> Supervisor.which_children
|> Enum.map(&game_state/1)
|> Enum.reject(fn x -> x end)
|> Enum.filter(fn x -> x end)
end

defp game_state({_id, pid, _type, _modules}) do
Expand Down
8 changes: 3 additions & 5 deletions lib/codebattle_web/templates/game/index.html.slim
Expand Up @@ -14,11 +14,9 @@ h2 Listing games
br

= for game <- @games do
- data = game.data
- first_player = data.first_player.name
- second_player = data.second_player.name
div= "id: #{data.id}, state: #{game.state}, players: #{first_player}, #{second_player}."
= link to: game_path(@conn, :show, data.id) do
- users = get_users(game) |> Enum.map(fn(x) -> x.name end) |> Enum.join(", ")
div= "id: #{game.data.id}, state: #{game.state}, players: #{users}."
= link to: game_path(@conn, :show, game.data.id) do
| <%= gettext "Join" %>
end
br
6 changes: 4 additions & 2 deletions lib/codebattle_web/templates/game/show.html.slim
Expand Up @@ -2,8 +2,10 @@ h1= "Game: #{@game.data.id}"
h2= "State: #{@game.state}"
p Users:
ul
li= @game.data.first_player.name
li= @game.data.second_player.name
- users = get_users(@game)
= for user <- users do
li= user.name
end

= link to: game_path(@conn, :index) do
| <%= gettext "Back to list" %>
Expand Down
5 changes: 5 additions & 0 deletions lib/codebattle_web/views/game_view.ex
@@ -1,3 +1,8 @@
defmodule CodebattleWeb.GameView do
use Codebattle.Web, :view

def get_users(game) do
[game.data.first_player, game.data.second_player]
|> Enum.filter(fn x -> x end)
end
end

0 comments on commit e0aaa65

Please sign in to comment.