pokemon-couture/lib/pokemon_couture_web/live/clothes_tracker_live.ex

39 lines
1.1 KiB
Elixir
Raw Normal View History

2021-09-08 16:30:37 +02:00
defmodule PokemonCoutureWeb.ClothesTrackerLive do
use PokemonCoutureWeb, :live_view
2021-09-13 14:36:14 +02:00
alias PokemonCouture.Shops
alias PokemonCouture.Shops.Clothes
alias PokemonCouture.Live.Components.ClothesComponent
2021-09-14 17:24:08 +02:00
alias PokemonCouture.Accounts
2021-09-13 14:36:14 +02:00
def create_shop_map(clothes, map) do
case map[clothes.location] do
nil ->
Map.put(map, clothes.location, [clothes])
list_of_clothes when is_list(list_of_clothes) ->
Map.put(map, clothes.location, list_of_clothes ++ [clothes])
end
end
2021-09-14 17:24:08 +02:00
def mount(_params, session, socket) do
user = Accounts.get_user_by_session_token(session["user_token"])
clothes_map = Enum.reduce(Shops.list_clothes_with_owners(), %{}, &create_shop_map/2)
2021-09-08 16:49:52 +02:00
socket =
socket
2021-09-14 17:24:08 +02:00
|> assign(:clothes_map, clothes_map)
|> assign(:user, user)
2021-09-08 16:30:37 +02:00
{:ok, socket}
end
def handle_event("on", _value, socket) do
socket =
socket
|> assign(:light_bulb_status, "on")
2021-09-08 16:49:52 +02:00
|> assign(:on_button_status, "disabled")
|> assign(:off_button_status, "enabled")
2021-09-08 16:30:37 +02:00
{:noreply, socket}
end
2021-09-08 16:49:52 +02:00
2021-09-08 16:30:37 +02:00
end