diff --git a/lib/music_library_web/components/record_components.ex b/lib/music_library_web/components/record_components.ex index 9f77c0b2..ae5c4821 100644 --- a/lib/music_library_web/components/record_components.ex +++ b/lib/music_library_web/components/record_components.ex @@ -199,49 +199,11 @@ defmodule MusicLibraryWeb.RecordComponents do <.focus_wrap id={"actions-#{record.id}-focus-wrap"} class="pointer-events-auto"> - <.dropdown_link id={"actions-#{record.id}-edit"} patch={@record_edit_path.(record)}> - <.icon - name="hero-pencil-square" - class="phx-click-loading:animate-bounce mr-1 size-4" - aria-hidden="true" - data-slot="icon" - /> - {gettext("Edit")} - - - <.dropdown_link - :if={!record.purchased_at} - id={"actions-#{record.id}-purchase"} - phx-click={ - JS.dispatch("music_library:confetti") - |> JS.push("add-to-collection", value: %{id: record.id}) - } - > - <.icon - name="hero-banknotes" - class="phx-click-loading:animate-shake mr-1 size-4" - aria-hidden="true" - data-slot="icon" - /> - {gettext("Purchased")} - - <.dropdown_separator /> - <.dropdown_link - id={"actions-#{record.id}-delete"} - phx-click={JS.push("delete", value: %{id: record.id}) |> hide("##{id}")} - data-confirm={gettext("Are you sure?")} - class={[ - "text-red-900! hover:bg-red-50! dark:text-red-500! dark:hover:bg-red-900/30! dark:hover:text-red-600!" - ]} - > - <.icon - name="hero-trash" - class="phx-click-loading:animate-spin mr-1 size-4" - aria-hidden="true" - data-slot="icon" - /> - {gettext("Delete")} - + <.record_action_links + record={record} + edit_path={@record_edit_path.(record)} + hide_target={"##{id}"} + /> @@ -320,50 +282,11 @@ defmodule MusicLibraryWeb.RecordComponents do /> <.focus_wrap id={"actions-#{record.id}-focus-wrap"}> - <.dropdown_link - id={"actions-#{record.id}-edit"} - patch={@record_edit_path.(record)} - > - <.icon - name="hero-pencil-square" - class="phx-click-loading:animate-bounce mr-1 size-4" - aria-hidden="true" - data-slot="icon" - /> - {gettext("Edit")} - - - <.dropdown_link - :if={!record.purchased_at} - id={"actions-#{record.id}-purchase"} - phx-click={ - JS.dispatch("music_library:confetti") - |> JS.push("add-to-collection", value: %{id: record.id}) - } - > - <.icon - name="hero-banknotes" - class="phx-click-loading:animate-shake mr-1 size-4" - aria-hidden="true" - data-slot="icon" - /> - {gettext("Purchased")} - - <.dropdown_separator /> - <.dropdown_link - id={"actions-#{record.id}-delete"} - phx-click={JS.push("delete", value: %{id: record.id}) |> hide("##{id}")} - data-confirm={gettext("Are you sure?")} - class="text-red-900! hover:bg-red-50! dark:text-red-500! dark:hover:bg-red-900/30! dark:hover:text-red-600!" - > - <.icon - name="hero-trash" - class="phx-click-loading:animate-spin mr-1 size-4" - aria-hidden="true" - data-slot="icon" - /> - {gettext("Delete")} - + <.record_action_links + record={record} + edit_path={@record_edit_path.(record)} + hide_target={"##{id}"} + /> @@ -747,6 +670,56 @@ defmodule MusicLibraryWeb.RecordComponents do """ end + attr :record, :map, required: true + attr :edit_path, :string, required: true + attr :hide_target, :string, required: true + + defp record_action_links(assigns) do + ~H""" + <.dropdown_link id={"actions-#{@record.id}-edit"} patch={@edit_path}> + <.icon + name="hero-pencil-square" + class="phx-click-loading:animate-bounce mr-1 size-4" + aria-hidden="true" + data-slot="icon" + /> + {gettext("Edit")} + + + <.dropdown_link + :if={!@record.purchased_at} + id={"actions-#{@record.id}-purchase"} + phx-click={ + JS.dispatch("music_library:confetti") + |> JS.push("add-to-collection", value: %{id: @record.id}) + } + > + <.icon + name="hero-banknotes" + class="phx-click-loading:animate-shake mr-1 size-4" + aria-hidden="true" + data-slot="icon" + /> + {gettext("Purchased")} + + <.dropdown_separator /> + <.dropdown_link + id={"actions-#{@record.id}-delete"} + phx-click={JS.push("delete", value: %{id: @record.id}) |> hide(@hide_target)} + data-confirm={gettext("Are you sure?")} + class="text-red-900! hover:bg-red-50! dark:text-red-500! dark:hover:bg-red-900/30! dark:hover:text-red-600!" + > + <.icon + name="hero-trash" + class="phx-click-loading:animate-spin mr-1 size-4" + aria-hidden="true" + data-slot="icon" + /> + {gettext("Delete")} + + """ + end + defp genre_search_path(:collection, genre), do: ~p"/collection?#{%{query: ~s(genre:"#{genre}")}}"