From 11ddba79e3713b6517246e209a92eb8d3079e74f Mon Sep 17 00:00:00 2001 From: shibao Date: Sat, 12 Feb 2022 00:36:55 -0500 Subject: [PATCH] add actions as render block in tag card --- lib/cannery_web/components/tag_card.ex | 16 +--------------- lib/cannery_web/live/tag_live/index.ex | 4 ++-- lib/cannery_web/live/tag_live/index.html.heex | 17 ++++++++++++++++- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/lib/cannery_web/components/tag_card.ex b/lib/cannery_web/components/tag_card.ex index d3d4a2c0..d4b54714 100644 --- a/lib/cannery_web/components/tag_card.ex +++ b/lib/cannery_web/components/tag_card.ex @@ -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 %> - <%= live_patch to: Routes.tag_index_path(Endpoint, :edit, @tag), - class: "text-primary-500 link" do %> - - <% 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 %> - - <% end %> + <%= render_slot(@inner_block) %> """ end diff --git a/lib/cannery_web/live/tag_live/index.ex b/lib/cannery_web/live/tag_live/index.ex index 5f0ce2ef..e8ceb8a5 100644 --- a/lib/cannery_web/live/tag_live/index.ex +++ b/lib/cannery_web/live/tag_live/index.ex @@ -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 diff --git a/lib/cannery_web/live/tag_live/index.html.heex b/lib/cannery_web/live/tag_live/index.html.heex index 50589ebd..6a070cae 100644 --- a/lib/cannery_web/live/tag_live/index.html.heex +++ b/lib/cannery_web/live/tag_live/index.html.heex @@ -22,7 +22,22 @@ <% end %>
<%= 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 %> + + <% 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 %> + + <% end %> + <% end %>