Skip to content

Commit

Permalink
Merge in new lobby styling
Browse files Browse the repository at this point in the history
References #22
  • Loading branch information
Amber-K committed Nov 18, 2021
2 parents 888a6ea + b3e74a6 commit 4ac70d8
Show file tree
Hide file tree
Showing 13 changed files with 216 additions and 185 deletions.
5 changes: 5 additions & 0 deletions assets/css/phoenix.css
Original file line number Diff line number Diff line change
Expand Up @@ -569,3 +569,8 @@ select {
.red-team-awards {
background-color: red;
}

#player-info-text {
top: 16px;
right: 16px;
}
19 changes: 18 additions & 1 deletion assets/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,24 @@ import topbar from "topbar"
import {LiveSocket} from "phoenix_live_view"

let Hooks = {}
Hooks.header = {
mounted() {
this.handleEvent("updateHeader", (payload) => {
var playerInfo = document.getElementById("player-info");
var playerInfoText = document.getElementById("player-info-text");
playerInfo.className = "";
let team = payload.team.charAt(0).toUpperCase() + payload.team.slice(1);
let role = "Player";
if (payload.is_admin) {
role = "Game Admin";
} else if (payload.team_leader == "red" || payload.team_leader == "blue") {
role = "Team Leader";
}
playerInfoText.textContent = "Player: " + payload.name + " | Team: " + team + " | Role: " + role;
})
}
}

Hooks.Spinner = {

beforeUpdate() {
Expand All @@ -36,7 +54,6 @@ let liveSocket = new LiveSocket("/live", Socket, {hooks: Hooks, params: {_csrf_t
topbar.config({barColors: {0: "#29d"}, shadowColor: "rgba(0, 0, 0, .3)"})
window.addEventListener("phx:page-loading-start", info => topbar.show())
window.addEventListener("phx:page-loading-stop", info => topbar.hide())

// connect if there are any LiveViews on the page
liveSocket.connect()

Expand Down
6 changes: 6 additions & 0 deletions lib/dream_up/players.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ defmodule DreamUp.Players do

import Ecto.Query, warn: false
alias DreamUp.Repo
import Phoenix.LiveView

alias DreamUp.Players.Player

Expand Down Expand Up @@ -144,4 +145,9 @@ defmodule DreamUp.Players do
-1
end
end

def push_header_event(socket, player) do
push_event(socket, "updateHeader", %{name: player.name, team: player.team, team_leader: player.team_leader, is_admin: player.game_admin})
end

end
2 changes: 1 addition & 1 deletion lib/dream_up_web/live/awards_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ defmodule DreamUpWeb.AwardsLive do
if status !== :ok do
{:noreply, redirect(new_socket, to: route)}
else
{:noreply, new_socket}
{:noreply, Players.push_header_event(new_socket, new_socket.assigns.player)}
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/dream_up_web/live/awards_live.html.leex
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
</div>
</div>
<% end %>
<div class="grid sm:grid-cols-3 lg:grid-cols-5 gap-4">
<div phx-hook="header" class="grid sm:grid-cols-3 lg:grid-cols-5 gap-4">
<%= for card <- @cards do %>
<%= if card.type == "Award" do %>
<div class="card award">
Expand Down
6 changes: 3 additions & 3 deletions lib/dream_up_web/live/board_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ defmodule DreamUpWeb.BoardLive do
{:noreply, redirect(socket, to: route)}
else
if game.round_number === 0 do
socket = assign(socket, player: player, game: game, method_card: nil)
socket = assign(Players.push_header_event(socket, player), player: player, game: game, method_card: nil)
if player.game_admin do
{:noreply, countdown(socket)}
else
{:noreply, socket}
end
else
if player.game_admin do
{:noreply, countdown(assign(socket, player: player, game: game, method_card: Cards.get_card!(Enum.at(Games.get_method_card_list(game), game.round_number - 1)), method_cards: method_cards))}
{:noreply, countdown(assign(Players.push_header_event(socket, player), player: player, game: game, method_card: Cards.get_card!(Enum.at(Games.get_method_card_list(game), game.round_number - 1)), method_cards: method_cards))}
else
{:noreply, assign(socket, player: player, game: game, method_card: Cards.get_card!(Enum.at(Games.get_method_card_list(game), game.round_number - 1)), method_cards: method_cards)}
{:noreply, assign(Players.push_header_event(socket, player), player: player, game: game, method_card: Cards.get_card!(Enum.at(Games.get_method_card_list(game), game.round_number - 1)), method_cards: method_cards)}
end
end
end
Expand Down
15 changes: 2 additions & 13 deletions lib/dream_up_web/live/board_live.html.leex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div id="board">
<div id="board" phx-hook="header">
<div class="grid md:grid-cols-3 gap-4">
<div>
<div class="py-2 mb-2 text-center border-2 border-indigo-600 rounded">
Expand Down Expand Up @@ -200,15 +200,4 @@
</div>
<% end %>
</div>
</div>

<script>
window.addEventListener("phx:page-loading-stop", info => topbar.hide())
animate_spinner(class_to_add) {
var spinner = document.getElementById("spinner");
spinner.style.animation = 'none';
spinner.offsetHeight;
spinner.style.animation = null;
spinner.className = class_to_add;
}
</script>
</div>
2 changes: 1 addition & 1 deletion lib/dream_up_web/live/home_live.html.leex
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="grid grid-cols-2 gap-4">
<div id="header" phx-hook="header" class="grid grid-cols-2 gap-4">
<div class="px-8">
<h1 class="font-bold text-4xl pb-12">
Enter Game Code:
Expand Down
8 changes: 3 additions & 5 deletions lib/dream_up_web/live/lobby_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ defmodule DreamUpWeb.LobbyLive do
if status !== :ok do
{:noreply, redirect(socket, to: route)}
else
{:noreply, socket}
{:noreply, Players.push_header_event(socket, player)}
end
{:error, %Ecto.Changeset{} = changeset} ->
socket = assign(socket, changest: changeset)
Expand All @@ -86,8 +86,7 @@ defmodule DreamUpWeb.LobbyLive do

players = Players.list_players_in_game(socket.assigns.game_id)

socket = assign(socket, players: players, editing: false)
{:noreply, socket}
{:noreply, assign(Players.push_header_event(socket, Players.get_player!(socket.assigns.id)), players: players, editing: false)}
end

def handle_event("editing", %{"editing" => editing}, socket) do
Expand Down Expand Up @@ -119,8 +118,7 @@ defmodule DreamUpWeb.LobbyLive do

players = Players.list_players_in_game(socket.assigns.game_id)

socket = assign(socket, players: players)
{:noreply, socket}
{:noreply, assign(Players.push_header_event(socket, Players.get_player!(id)), players: players)}
end

def handle_event("begin-setup", _, socket) do
Expand Down
Loading

0 comments on commit 4ac70d8

Please sign in to comment.