add tracking saved to db

This commit is contained in:
2021-09-14 17:24:08 +02:00
parent 1af37846bd
commit 42e025af12
6 changed files with 36 additions and 19 deletions
@@ -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