add tracking saved to db
This commit is contained in:
@@ -1,10 +1,8 @@
|
||||
defmodule PokemonCoutureWeb.Components.ClothesComponent do
|
||||
use Phoenix.LiveComponent
|
||||
|
||||
alias PokemonCouture.Shops
|
||||
def mount(socket) do
|
||||
socket =
|
||||
socket
|
||||
|> assign(active: true)
|
||||
{:ok, socket}
|
||||
end
|
||||
|
||||
@@ -20,13 +18,12 @@ defmodule PokemonCoutureWeb.Components.ClothesComponent do
|
||||
phx-click="toggle-active"
|
||||
phx-target="<%= @myself %>"
|
||||
>
|
||||
<%= if @active do %>
|
||||
Got it
|
||||
<% else %>
|
||||
<%= if @user in @clothes.users do %>
|
||||
X
|
||||
<% else %>
|
||||
Got it
|
||||
<% end %>
|
||||
</button>
|
||||
<!-- here be acquire buton -->
|
||||
</td>
|
||||
</tr>
|
||||
"""
|
||||
@@ -34,9 +31,12 @@ defmodule PokemonCoutureWeb.Components.ClothesComponent do
|
||||
|
||||
|
||||
def handle_event("toggle-active", _value, socket) do
|
||||
socket =
|
||||
socket
|
||||
|> assign(:active, not socket.assigns.active)
|
||||
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)
|
||||
{:noreply, socket}
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user