Skip to content

Commit

Permalink
Part 5 step 2 LiveView GameDetail + Row Ddragon GridElement components 🍾
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdotb committed Sep 25, 2022
1 parent 6ce55d9 commit 052cec3
Show file tree
Hide file tree
Showing 6 changed files with 325 additions and 64 deletions.
27 changes: 25 additions & 2 deletions assets/css/app.css
Expand Up @@ -3,8 +3,7 @@
@import "tailwindcss/components";
@import "tailwindcss/utilities";

/* Custom grid for participants */

/* Custom grids */
.grid-participants-header {
display: none;
}
Expand All @@ -13,6 +12,10 @@
display: grid;
grid-template-columns: 11% 17% 12% 10% 10% 35% 4%;
}
.grid-team-participants-header {
display: grid;
grid-template-columns: 25% 11% 12% 12% 40%;
}
}
.grid-participants {
display: grid;
Expand All @@ -23,12 +26,26 @@
"player kda versus"
"creation summoners build";
}
.grid-team-participants {
display: grid;
grid-gap: 3px 0px;
grid-template-rows: auto auto;
grid-template-columns: 60% 20% 20%;
grid-template-areas:
"summoner-champion kda summoners"
"build . gold";
}
@media (min-width: theme('screens.md')) {
.grid-participants {
grid-gap: 0px;
grid-template-columns: 11% 17% 12% 10% 10% 35% 4%;
grid-template-areas: "creation player versus kda summoners build ellipsis";
}
.grid-team-participants {
grid-gap: 0px;
grid-template-columns: 25% 11% 12% 12% 40%;
grid-template-areas: "summoner-champion summoners kda gold build ";
}
}
.grid-area-creation {
grid-area: creation;
Expand All @@ -51,6 +68,12 @@
.grid-area-ellipsis {
grid-area: ellipsis;
}
.grid-area-summoner-champion {
grid-area: summoner-champion;
}
.grid-area-gold {
grid-area: gold;
}

/* Alerts and form errors used by phx.new */
.alert {
Expand Down
39 changes: 39 additions & 0 deletions lib/probuild_ex_web/live/game_live/ddragon_component.ex
@@ -0,0 +1,39 @@
defmodule ProbuildExWeb.GameLive.DdragonComponent do
@moduledoc false

use Phoenix.Component

alias ProbuildEx.Ddragon

def champion(assigns) do
~H"""
<div class="w-8 h-8 rounded-full overflow-hidden bg-gray-900">
<img src={Ddragon.get_champion_image(@game_version, @champion_id)} class="w-full" />
</div>
"""
end

def summoner(assigns) do
~H"""
<div class="w-8 h-8 rounded-full overflow-hidden bg-gray-900">
<img src={Ddragon.get_summoner_image(@game_version, @summoner_key)} class="w-full" />
</div>
"""
end

def item(assigns) do
~H"""
<div class="bg-gray-900 w-8 h-8 border border-gray-400">
<%= if src = Ddragon.get_item_image(@game_version, @item_key) do %>
<img src={src} class="w-full" />
<% end %>
</div>
"""
end

def spinner(assigns) do
~H"""
<img class={if not @load?, do: "invisible"} src="https://developer.riotgames.com/static/img/katarina.55a01cf0560a.gif" />
"""
end
end
115 changes: 115 additions & 0 deletions lib/probuild_ex_web/live/game_live/grid_element_component.ex
@@ -0,0 +1,115 @@
defmodule ProbuildExWeb.GameLive.GridElementComponent do
@moduledoc false

use Phoenix.Component

import ProbuildExWeb.GameLive.DdragonComponent

def time_ago(assigns) do
~H"""
<div class="grid-area-creation flex md:justify-center items-center">
<time id={["time", to_string(@participant_id)]} phx-hook="TimeAgo" datetime={@game_creation}></time>
</div>
"""
end

def pro_name(assigns) do
~H"""
<div class="grid-area-player flex items-center">
<!-- Heroicon name: user-circle -->
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="w-8 h-8">
<path fill-rule="evenodd" d="M18.685 19.097A9.723 9.723 0 0021.75 12c0-5.385-4.365-9.75-9.75-9.75S2.25 6.615 2.25 12a9.723 9.723 0 003.065 7.097A9.716 9.716 0 0012 21.75a9.716 9.716 0 006.685-2.653zm-12.54-1.285A7.486 7.486 0 0112 15a7.486 7.486 0 015.855 2.812A8.224 8.224 0 0112 20.25a8.224 8.224 0 01-5.855-2.438zM15.75 9a3.75 3.75 0 11-7.5 0 3.75 3.75 0 017.5 0z" clip-rule="evenodd" />
</svg>
<span class="flex-1 ml-1 text-ellipsis overflow-hidden">
<%= @pro_name %>
</span>
</div>
"""
end

def versus(assigns) do
~H"""
<div class="grid-area-versus flex justify-center items-center space-x-1">
<.champion game_version={@game_version} champion_id={@champion_id} />
<span>vs</span>
<.champion game_version={@game_version} champion_id={@opponent_champion_id} />
</div>
"""
end

def kda(assigns) do
~H"""
<div class="grid-area-kda flex justify-center items-center">
<span class="font-medium">
<%= @kills %>
</span>
/
<span class="font-medium text-red-500">
<%= @deaths %>
</span>
/
<span class="font-medium">
<%= @assists %>
</span>
</div>
"""
end

def summoners(assigns) do
~H"""
<div class="grid-area-summoners flex justify-center items-center space-x-1">
<%= for summoner_key <- @summoners do %>
<.summoner game_version={@game_version} summoner_key={summoner_key} />
<% end %>
</div>
"""
end

def items(assigns) do
~H"""
<div class="grid-area-build flex justify-center items-center space-x-1">
<%= for item_key <- @items do %>
<.item game_version={@game_version} item_key={item_key} />
<% end %>
</div>
"""
end

def ellipsis(assigns) do
~H"""
<div class="grid-area-ellipsis hidden md:flex flex-1 justify-center items-center">
<!-- Heroicon name: ellipsis-vertical -->
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="w-6 h-6">
<path fill-rule="evenodd" d="M4.5 12a1.5 1.5 0 113 0 1.5 1.5 0 01-3 0zm6 0a1.5 1.5 0 113 0 1.5 1.5 0 01-3 0zm6 0a1.5 1.5 0 113 0 1.5 1.5 0 01-3 0z" clip-rule="evenodd" />
</svg>
</div>
"""
end

def champion_block(assigns) do
~H"""
<div class="grid-area-champion">
<.champion game_version={@game_version} champion_id={@champion_id} />
</div>
"""
end

def summoner_champion(assigns) do
~H"""
<div class="grid-area-summoner-name flex items-center">
<.champion game_version={@game_version} champion_id={@champion_id} />
<span class="ml-1 text-ellipsis overflow-hidden whitespace-nowrap">
<%= @summoner_name %>
</span>
</div>
"""
end

def gold_earned(assigns) do
~H"""
<div class="grid-area-gold flex justify-center items-center text-yellow-600">
<%= @gold_earned %>
</div>
"""
end
end
4 changes: 3 additions & 1 deletion lib/probuild_ex_web/live/game_live/index.ex
Expand Up @@ -2,7 +2,9 @@ defmodule ProbuildExWeb.GameLive.Index do
use ProbuildExWeb, :live_view

alias ProbuildEx.App
alias ProbuildEx.Ddragon
alias ProbuildExWeb.GameLive.RowComponent

import ProbuildExWeb.GameLive.DdragonComponent

@defaults %{
page_title: "Listing games",
Expand Down
64 changes: 3 additions & 61 deletions lib/probuild_ex_web/live/game_live/index.html.heex
Expand Up @@ -36,7 +36,7 @@
<%= cond do %>
<% @loading? -> %>
<div class="w-full max-w-3xl py-2 flex justify-center">
<img src="https://developer.riotgames.com/static/img/katarina.55a01cf0560a.gif" />
<.spinner load?={@loading?} />
</div>

<% length(@participants) == 0 -> %>
Expand All @@ -55,70 +55,12 @@
</div>
<div id="participants" phx-update={@update} class="w-full max-w-3xl flex-1 flex flex-col items-center space-y-1">
<%= for participant <- @participants do %>
<div id={"participant-#{participant.id}"} class={[if(participant.win, do: "border-blue-500", else: "border-red-500"), "hover:bg-gray-100 hover:cursor-pointer border-l-8 w-full max-w-3xl grid-participants px-1 py-2 bg-white rounded-lg overflow-hidden shadow"]}>
<div class="grid-area-creation flex md:justify-center items-center">
<time id={"time-ago-#{participant.id}"} phx-hook="TimeAgo" datetime={participant.game.creation}></time>
</div>

<div class="grid-area-player flex items-center">
<!-- Heroicon name: user-circle -->
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="w-8 h-8">
<path fill-rule="evenodd" d="M18.685 19.097A9.723 9.723 0 0021.75 12c0-5.385-4.365-9.75-9.75-9.75S2.25 6.615 2.25 12a9.723 9.723 0 003.065 7.097A9.716 9.716 0 0012 21.75a9.716 9.716 0 006.685-2.653zm-12.54-1.285A7.486 7.486 0 0112 15a7.486 7.486 0 015.855 2.812A8.224 8.224 0 0112 20.25a8.224 8.224 0 01-5.855-2.438zM15.75 9a3.75 3.75 0 11-7.5 0 3.75 3.75 0 017.5 0z" clip-rule="evenodd" />
</svg>
<span class="flex-1 ml-1 text-ellipsis overflow-hidden">
<%= participant.summoner.pro.name %>
</span>
</div>

<div class="grid-area-versus flex justify-center items-center space-x-1">
<%= img_tag(Ddragon.get_champion_image(participant.game.version, participant.champion_id), class: "w-8 h-8 rounded-full") %>
<span>vs</span>
<%= img_tag(Ddragon.get_champion_image(participant.game.version, participant.opponent_participant.champion_id), class: "w-8 h-8 rounded-full") %>
</div>

<div class="grid-area-kda flex justify-center items-center">
<span class="font-medium">
<%= participant.kills %>
</span>
/
<span class="font-medium text-red-500">
<%= participant.deaths %>
</span>
/
<span class="font-medium">
<%= participant.assists %>
</span>
</div>

<div class="grid-area-summoners flex justify-center items-center space-x-1">
<%= for summoner_key <- participant.summoners do %>
<%= img_tag(Ddragon.get_summoner_image(participant.game.version, summoner_key), class: "w-8 h-8 border border-gray-400") %>
<% end %>
</div>

<div class="grid-area-build flex justify-center items-center space-x-1">
<%= for item_key <- participant.items do %>
<%= if src = Ddragon.get_item_image(participant.game.version, item_key) do %>
<img src={src} class="w-8 h-8" />
<% else %>
<div class="bg-gray-900 w-8 h-8 border border-gray-400"></div>
<% end %>
<% end %>
</div>

<div class="grid-area-ellipsis hidden md:flex flex-1 justify-center items-center">
<!-- Heroicon name: ellipsis-vertical -->
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor" class="w-6 h-6">
<path fill-rule="evenodd" d="M4.5 12a1.5 1.5 0 113 0 1.5 1.5 0 01-3 0zm6 0a1.5 1.5 0 113 0 1.5 1.5 0 01-3 0zm6 0a1.5 1.5 0 113 0 1.5 1.5 0 01-3 0z" clip-rule="evenodd" />
</svg>
</div>

</div>
<.live_component id={participant.id} module={RowComponent} participant={participant} />
<% end %>
</div>
<% end %>
<div id="infinite-scroll" phx-hook="InfiniteScroll" data-page={@page.page_number} class="w-full max-w-3xl py-2 flex justify-center">
<img class={if not @load_more?, do: "invisible"} src="https://developer.riotgames.com/static/img/katarina.55a01cf0560a.gif" />
<.spinner load?={@load_more?} />
</div>
</div>

Expand Down

0 comments on commit 052cec3

Please sign in to comment.