mirror of
https://github.com/danbee/chess
synced 2025-03-04 08:39:06 +00:00
WIP: Game info
This commit is contained in:
parent
3543ccdcae
commit
87504064e7
6
lib/chess_web/templates/game/game_info.html.leex
Normal file
6
lib/chess_web/templates/game/game_info.html.leex
Normal file
@ -0,0 +1,6 @@
|
||||
<div class="game-info">
|
||||
<p>
|
||||
Playing <%= opponent(@game, @user.id).name %>
|
||||
<img class="game-info__opponent-status" src="/images/eye-closed.svg" alt="offline">
|
||||
</p>
|
||||
</div>
|
||||
@ -6,12 +6,11 @@
|
||||
session: %{"user_id" => current_user(@conn).id, "game_id" => @game.id}
|
||||
) %>
|
||||
|
||||
<div class="game-info">
|
||||
<p>
|
||||
Playing <%= opponent(@game, current_user(@conn).id).name %>
|
||||
<img class="game-info__opponent-status" src="/images/eye-closed.svg" alt="offline">
|
||||
</p>
|
||||
</div>
|
||||
<%= live_render(
|
||||
@conn,
|
||||
ChessWeb.GameInfoLive,
|
||||
session: %{"user_id" => current_user(@conn).id, "game_id" => @game.id}
|
||||
) %>
|
||||
|
||||
<div class="move-list">
|
||||
<table class="table table--condensed">
|
||||
|
||||
21
lib/chess_web/views/live/game_info_live.ex
Normal file
21
lib/chess_web/views/live/game_info_live.ex
Normal file
@ -0,0 +1,21 @@
|
||||
defmodule ChessWeb.GameInfoLive do
|
||||
use Phoenix.LiveView
|
||||
|
||||
alias Chess.Store.User
|
||||
alias Chess.Store.Game
|
||||
alias Chess.Repo
|
||||
|
||||
def render(assigns) do
|
||||
Phoenix.View.render(ChessWeb.GameView, "game_info.html", assigns)
|
||||
end
|
||||
|
||||
def mount(_params, %{"game_id" => game_id, "user_id" => user_id}, socket) do
|
||||
user = Repo.get!(User, user_id)
|
||||
|
||||
game =
|
||||
Game.for_user(user)
|
||||
|> Repo.get!(game_id)
|
||||
|
||||
{:ok, assign(socket, game: game, user: user)}
|
||||
end
|
||||
end
|
||||
Loading…
Reference in New Issue
Block a user