2021-09-13 14:36:14 +02:00
|
|
|
defmodule PokemonCoutureWeb.Components.ClothesComponent do
|
|
|
|
use Phoenix.LiveComponent
|
|
|
|
|
2021-09-14 17:24:08 +02:00
|
|
|
alias PokemonCouture.Shops
|
2021-09-13 14:36:14 +02:00
|
|
|
|
|
|
|
def render(assigns) do
|
|
|
|
~L"""
|
|
|
|
<tr>
|
|
|
|
<td><%= @clothes.name %></td>
|
|
|
|
<td><%= @clothes.color %></td>
|
2021-09-24 14:43:41 +02:00
|
|
|
<td><%= @clothes.type %></td>
|
2021-09-13 14:36:14 +02:00
|
|
|
<td><%= @clothes.game %></td>
|
|
|
|
|
|
|
|
<td>
|
|
|
|
<button
|
|
|
|
phx-click="toggle-active"
|
|
|
|
phx-target="<%= @myself %>"
|
|
|
|
>
|
2021-09-14 17:24:08 +02:00
|
|
|
<%= if @user in @clothes.users do %>
|
2021-09-13 14:36:14 +02:00
|
|
|
X
|
2021-09-14 17:24:08 +02:00
|
|
|
<% else %>
|
|
|
|
Got it
|
2021-09-13 14:36:14 +02:00
|
|
|
<% end %>
|
|
|
|
</button>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
"""
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
def handle_event("toggle-active", _value, socket) do
|
2021-09-14 17:24:08 +02:00
|
|
|
new_clothes = if socket.assigns.user in socket.assigns.clothes.users do
|
|
|
|
Shops.remove_owner(socket.assigns.clothes, socket.assigns.user)
|
|
|
|
else
|
|
|
|
Shops.add_owner(socket.assigns.clothes, socket.assigns.user)
|
|
|
|
end
|
|
|
|
socket = assign(socket, :clothes, new_clothes)
|
2021-09-13 14:36:14 +02:00
|
|
|
{:noreply, socket}
|
|
|
|
end
|
|
|
|
end
|