diff --git a/assets/css/phoenix.css b/assets/css/phoenix.css index f95e1f6..708752f 100644 --- a/assets/css/phoenix.css +++ b/assets/css/phoenix.css @@ -569,3 +569,8 @@ select { .red-team-awards { background-color: red; } + +#player-info-text { + top: 16px; + right: 16px; +} \ No newline at end of file diff --git a/assets/js/app.js b/assets/js/app.js index 71012d0..73b0dab 100644 --- a/assets/js/app.js +++ b/assets/js/app.js @@ -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() { @@ -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() diff --git a/lib/dream_up/players.ex b/lib/dream_up/players.ex index cd0fab4..3c99166 100644 --- a/lib/dream_up/players.ex +++ b/lib/dream_up/players.ex @@ -5,6 +5,7 @@ defmodule DreamUp.Players do import Ecto.Query, warn: false alias DreamUp.Repo + import Phoenix.LiveView alias DreamUp.Players.Player @@ -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 diff --git a/lib/dream_up_web/live/awards_live.ex b/lib/dream_up_web/live/awards_live.ex index 63cd257..2c6f756 100644 --- a/lib/dream_up_web/live/awards_live.ex +++ b/lib/dream_up_web/live/awards_live.ex @@ -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 diff --git a/lib/dream_up_web/live/awards_live.html.leex b/lib/dream_up_web/live/awards_live.html.leex index 6e35c61..084a321 100644 --- a/lib/dream_up_web/live/awards_live.html.leex +++ b/lib/dream_up_web/live/awards_live.html.leex @@ -65,7 +65,7 @@ <% end %> -
+
<%= for card <- @cards do %> <%= if card.type == "Award" do %>
diff --git a/lib/dream_up_web/live/board_live.ex b/lib/dream_up_web/live/board_live.ex index 1860763..9d682a9 100644 --- a/lib/dream_up_web/live/board_live.ex +++ b/lib/dream_up_web/live/board_live.ex @@ -30,7 +30,7 @@ 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 @@ -38,9 +38,9 @@ defmodule DreamUpWeb.BoardLive do 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 diff --git a/lib/dream_up_web/live/board_live.html.leex b/lib/dream_up_web/live/board_live.html.leex index 7f38377..ac4e713 100644 --- a/lib/dream_up_web/live/board_live.html.leex +++ b/lib/dream_up_web/live/board_live.html.leex @@ -1,4 +1,4 @@ -
+
@@ -200,15 +200,4 @@
<% end %>
-
- - +
\ No newline at end of file diff --git a/lib/dream_up_web/live/home_live.html.leex b/lib/dream_up_web/live/home_live.html.leex index 4407285..5401f1f 100644 --- a/lib/dream_up_web/live/home_live.html.leex +++ b/lib/dream_up_web/live/home_live.html.leex @@ -1,4 +1,4 @@ -
+