sort clothes in tracker by type

This commit is contained in:
Lili (Tlapka) 2021-09-24 16:44:36 +02:00
parent a8d30550ab
commit 997e4b4904
3 changed files with 26 additions and 19 deletions

View File

@ -7,9 +7,15 @@ defmodule PokemonCoutureWeb.ClothesTrackerLive do
def create_shop_map(clothes, map) do
case map[clothes.location] do
nil ->
Map.put(map, clothes.location, [clothes])
Map.put(map, clothes.location, %{clothes.type => [clothes]})
map_of_clothes when is_map(map_of_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, clothes.location, list_of_clothes ++ [clothes])
Map.put(map_of_clothes, clothes.type, [clothes | list_of_clothes])
end
Map.put(map, clothes.location, map_of_clothes)
end
end

View File

@ -1,12 +1,13 @@
<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>
<%= for {type, list_of_clothes} <- map_of_clothes_by_type do %>
<h3> <%= type %> </h3>
<table>
<thead>
<tr>
<th>Name</th>
<th>Color</th>
<th>Type</th>
<th>Game</th>
<th></th>
</tr>
@ -18,3 +19,4 @@
</tbody>
</table>
<% end %>
<% end %>

View File

@ -8,7 +8,6 @@ defmodule PokemonCoutureWeb.Components.ClothesComponent do
<tr>
<td><%= @clothes.name %></td>
<td><%= @clothes.color %></td>
<td><%= @clothes.type %></td>
<td><%= @clothes.game %></td>
<td>