sort clothes in tracker by type
This commit is contained in:
parent
a8d30550ab
commit
997e4b4904
|
@ -7,9 +7,15 @@ defmodule PokemonCoutureWeb.ClothesTrackerLive do
|
||||||
def create_shop_map(clothes, map) do
|
def create_shop_map(clothes, map) do
|
||||||
case map[clothes.location] do
|
case map[clothes.location] do
|
||||||
nil ->
|
nil ->
|
||||||
Map.put(map, clothes.location, [clothes])
|
Map.put(map, clothes.location, %{clothes.type => [clothes]})
|
||||||
list_of_clothes when is_list(list_of_clothes) ->
|
map_of_clothes when is_map(map_of_clothes) ->
|
||||||
Map.put(map, clothes.location, list_of_clothes ++ [clothes])
|
map_of_clothes = case map_of_clothes[clothes.type] do
|
||||||
|
nil ->
|
||||||
|
Map.put(map_of_clothes, clothes.type, [clothes])
|
||||||
|
list_of_clothes when is_list(list_of_clothes) ->
|
||||||
|
Map.put(map_of_clothes, clothes.type, [clothes | list_of_clothes])
|
||||||
|
end
|
||||||
|
Map.put(map, clothes.location, map_of_clothes)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,20 +1,22 @@
|
||||||
<h1>Listing Clothes</h1>
|
<h1>Listing Clothes</h1>
|
||||||
<%= for {shop, list_of_clothes} <- @clothes_map do %>
|
<%= for {shop, map_of_clothes_by_type} <- @clothes_map do %>
|
||||||
<h2> <%= shop %></h2>
|
<h2> <%= shop %></h2>
|
||||||
<table>
|
<%= for {type, list_of_clothes} <- map_of_clothes_by_type do %>
|
||||||
<thead>
|
<h3> <%= type %> </h3>
|
||||||
<tr>
|
<table>
|
||||||
<th>Name</th>
|
<thead>
|
||||||
<th>Color</th>
|
<tr>
|
||||||
<th>Type</th>
|
<th>Name</th>
|
||||||
<th>Game</th>
|
<th>Color</th>
|
||||||
<th></th>
|
<th>Game</th>
|
||||||
</tr>
|
<th></th>
|
||||||
</thead>
|
</tr>
|
||||||
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<%= for clothes <- list_of_clothes do %>
|
<%= for clothes <- list_of_clothes do %>
|
||||||
<%= live_component PokemonCoutureWeb.Components.ClothesComponent, id: clothes.id, clothes: clothes, user: @user %>
|
<%= live_component PokemonCoutureWeb.Components.ClothesComponent, id: clothes.id, clothes: clothes, user: @user %>
|
||||||
|
<% end %>
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -8,7 +8,6 @@ defmodule PokemonCoutureWeb.Components.ClothesComponent do
|
||||||
<tr>
|
<tr>
|
||||||
<td><%= @clothes.name %></td>
|
<td><%= @clothes.name %></td>
|
||||||
<td><%= @clothes.color %></td>
|
<td><%= @clothes.color %></td>
|
||||||
<td><%= @clothes.type %></td>
|
|
||||||
<td><%= @clothes.game %></td>
|
<td><%= @clothes.game %></td>
|
||||||
|
|
||||||
<td>
|
<td>
|
||||||
|
|
Loading…
Reference in New Issue