add actions as render block in tag card

This commit is contained in:
shibao 2022-02-12 00:36:55 -05:00
parent 332f92a02f
commit 11ddba79e3
3 changed files with 19 additions and 18 deletions

View File

@ -4,7 +4,6 @@ defmodule CanneryWeb.Components.TagCard do
"""
use CanneryWeb, :component
alias CanneryWeb.Endpoint
def tag_card(assigns) do
~H"""
@ -20,20 +19,7 @@ defmodule CanneryWeb.Components.TagCard do
<%= @tag.name %>
</h1>
<%= live_patch to: Routes.tag_index_path(Endpoint, :edit, @tag),
class: "text-primary-500 link" do %>
<i class="fa-fw fa-lg fas fa-edit"></i>
<% end %>
<%= link to: "#",
class: "text-primary-500 link",
phx_click: "delete",
phx_value_id: @tag.id,
data: [
confirm: dgettext("prompts", "Are you sure you want to delete %{name}?", name: @tag.name)
] do %>
<i class="fa-fw fa-lg fas fa-trash"></i>
<% end %>
<%= render_slot(@inner_block) %>
</div>
"""
end

View File

@ -5,8 +5,8 @@ defmodule CanneryWeb.TagLive.Index do
use CanneryWeb, :live_view
import CanneryWeb.Components.TagCard
alias Cannery.Tags
alias Cannery.Tags.Tag
alias Cannery.{Tags, Tags.Tag}
alias CanneryWeb.Endpoint
@impl true
def mount(_params, session, socket) do

View File

@ -22,7 +22,22 @@
<% end %>
<div class="flex flex-row flex-wrap">
<%= for tag <- @tags do %>
<.tag_card tag={tag} />
<.tag_card tag={tag}>
<%= live_patch to: Routes.tag_index_path(Endpoint, :edit, tag),
class: "text-primary-500 link" do %>
<i class="fa-fw fa-lg fas fa-edit"></i>
<% end %>
<%= link to: "#",
class: "text-primary-500 link",
phx_click: "delete",
phx_value_id: tag.id,
data: [
confirm: dgettext("prompts", "Are you sure you want to delete %{name}?", name: tag.name)
] do %>
<i class="fa-fw fa-lg fas fa-trash"></i>
<% end %>
</.tag_card>
<% end %>
</div>
</div>