add buttons to liveview thingy

This commit is contained in:
2021-09-13 14:36:14 +02:00
parent 85a31d3d02
commit 1af37846bd
3 changed files with 76 additions and 13 deletions
@@ -0,0 +1,42 @@
defmodule PokemonCoutureWeb.Components.ClothesComponent do
use Phoenix.LiveComponent
def mount(socket) do
socket =
socket
|> assign(active: true)
{:ok, socket}
end
def render(assigns) do
~L"""
<tr>
<td><%= @clothes.name %></td>
<td><%= @clothes.color %></td>
<td><%= @clothes.game %></td>
<td>
<button
phx-click="toggle-active"
phx-target="<%= @myself %>"
>
<%= if @active do %>
Got it
<% else %>
X
<% end %>
</button>
<!-- here be acquire buton -->
</td>
</tr>
"""
end
def handle_event("toggle-active", _value, socket) do
socket =
socket
|> assign(:active, not socket.assigns.active)
{:noreply, socket}
end
end