update summoner_spells component
Some checks are pending
ci / docker (push) Waiting to run

This commit is contained in:
Álvaro 2024-06-13 21:57:37 +02:00
parent 4823e68700
commit bd8148f3e2
4 changed files with 35 additions and 53 deletions

View File

@ -1,42 +0,0 @@
defmodule LolAnalyticsWeb.ChampionComponents.SummonerSpells.Props.SummonerSpell do
defstruct [:id, :name, :win_rate, :wins, :total_games, :image]
@type t :: %{
id: integer(),
win_rate: float(),
wins: integer(),
total_games: integer(),
image: String.t(),
name: String.t()
}
end
defmodule LolAnalyticsWeb.ChampionComponents.SummonerSpells.Props do
alias LolAnalyticsWeb.ChampionComponents.SummonerSpells.Props.SummonerSpell
defstruct spell: %SummonerSpell{}
@type t :: %{spell: SummonerSpell.t()}
end
defmodule LolAnalyticsWeb.ChampionComponents.SummonerSpell do
alias LolAnalyticsWeb.ChampionComponents.SummonerSpells.Props
use Phoenix.Component
attr :spells, Props, default: %Props{}
def summoner_spells(assigns) do
~H"""
<div class="flex flex-wrap flex-wrap gap-4">
<%= for spell <- assigns.spells.summoner_spells do %>
<div clas="flex flex-col gap-1">
<img src={spell.spell.image} />
<p><%= spell.spell.name %></p>
<p><%= spell.spell.win_rate %>%</p>
<p><%= spell.spell.wins %>/<%= spell.spell.total_games %></p>
</div>
<% end %>
</div>
"""
end
end

View File

@ -0,0 +1,19 @@
defmodule LolAnalyticsWeb.ChampionComponents.SummonerSpells do
alias LolAnalyticsWeb.ChampionComponents.SummonerSpells.Props
use Phoenix.Component
def summoner_spells(assigns) do
~H"""
<div class="flex flex-wrap flex-wrap gap-4">
<%= for spell <- assigns.spells.summoner_spells do %>
<div clas="flex flex-col gap-1">
<img src={spell.image} />
<p><%= spell.name %></p>
<p><%= spell.win_rate %>%</p>
<p><%= spell.wins %>/<%= spell.total_games %></p>
</div>
<% end %>
</div>
"""
end
end

View File

@ -1,7 +1,7 @@
defmodule LoLAnalyticsWeb.ChampionLive.Show do defmodule LoLAnalyticsWeb.ChampionLive.Show do
use LoLAnalyticsWeb, :live_view use LoLAnalyticsWeb, :live_view
import LolAnalyticsWeb.ChampionComponents.SummonerSpell import LolAnalyticsWeb.ChampionComponents.SummonerSpells
import LolAnalyticsWeb.ChampionComponents.ChampionAvatar import LolAnalyticsWeb.ChampionComponents.ChampionAvatar
alias LolAnalyticsWeb.ChampionComponents.SummonerSpells.ShowMapper alias LolAnalyticsWeb.ChampionComponents.SummonerSpells.ShowMapper
@ -26,6 +26,10 @@ defmodule LoLAnalyticsWeb.ChampionLive.Show do
LolAnalytics.Facts.ChampionPickedSummonerSpell.Repo.get_champion_picked_summoners(champion_id) LolAnalytics.Facts.ChampionPickedSummonerSpell.Repo.get_champion_picked_summoners(champion_id)
end end
defp load_items(champion_id) do
LolAnalytics.Facts.ChampionPickedItem.Repo.get_champion_picked_items(champion_id)
end
defp load_champion_info(champion_id) do defp load_champion_info(champion_id) do
champion = LolAnalytics.Dimensions.Champion.ChampionRepo.get_or_create(champion_id) champion = LolAnalytics.Dimensions.Champion.ChampionRepo.get_or_create(champion_id)

View File

@ -13,21 +13,22 @@ defmodule LolAnalyticsWeb.ChampionComponents.SummonerSpells.ShowMapper do
def map_spells(items) do def map_spells(items) do
items items
|> Enum.map(&map_spell/1) |> Enum.map(&map_spell/1)
|> Enum.sort(&(&1.spell.total_games > &2.spell.total_games)) |> Enum.sort(&(&1.total_games > &2.total_games))
end end
def map_spell(spell) do def map_spell(spell) do
image = spell.metadata["image"]["full"] image = spell.metadata["image"]["full"]
%LolAnalyticsWeb.ChampionComponents.SummonerSpells.Props{ %{
spell: %LolAnalyticsWeb.ChampionComponents.SummonerSpells.Props.SummonerSpell{ id: spell["id"],
id: spell.id, win_rate: :erlang.float_to_binary(spell.win_rate, decimals: 2),
win_rate: :erlang.float_to_binary(spell.win_rate, decimals: 2), total_games: spell.total_games,
total_games: spell.total_games, image: "https://ddragon.leagueoflegends.com/cdn/14.11.1/img/spell/#{image}",
image: "https://ddragon.leagueoflegends.com/cdn/14.11.1/img/spell/#{image}", name: spell.metadata["name"],
name: spell.metadata["name"], wins: spell.wins
wins: spell.wins
}
} }
end end
def map_item(item) do
end
end end