From 681db7686bf29d18d6660963a6e9c80b5ef78041 Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Wed, 28 May 2025 17:39:24 +0100 Subject: [PATCH] Add record menu dropdown to records in artist page --- .../components/record_components.ex | 105 +++++++++++++++++- .../live/artist_live/show.html.heex | 6 +- 2 files changed, 104 insertions(+), 7 deletions(-) diff --git a/lib/music_library_web/components/record_components.ex b/lib/music_library_web/components/record_components.ex index ecaa6b93..af7d922b 100644 --- a/lib/music_library_web/components/record_components.ex +++ b/lib/music_library_web/components/record_components.ex @@ -216,7 +216,8 @@ defmodule MusicLibraryWeb.RecordComponents do attr :records_count, :integer, required: true attr :title, :string, required: true attr :id, :string, required: true - attr :record_path, :any, required: true + attr :record_show_path, :any, required: true + attr :record_edit_path, :any, required: true def record_grid(assigns) do ~H""" @@ -260,14 +261,108 @@ defmodule MusicLibraryWeb.RecordComponents do -

- {record.title} -

+
+

+ {record.title} +

+
+ + + <.focus_wrap + id={"actions-#{record.id}"} + class={[ + "hidden pointer-events-auto absolute right-0 z-10 mt-2 w-48 origin-top-right rounded-md bg-white dark:bg-zinc-800 py-2 shadow-lg ring-1 ring-zinc-900/5 focus:outline-hidden" + ]} + role="menu" + aria-orientation="vertical" + aria-labelledby="options-menu-0-button" + > + <.link + class="block px-3 py-1 text-sm leading-6 text-zinc-900 dark:text-zinc-400 hover:bg-zinc-50 dark:hover:text-zinc-300 dark:hover:bg-zinc-700" + role="menuitem" + tabindex="0" + id={"actions-#{record.id}-show"} + navigate={@record_show_path.(record)} + > + {gettext("Show")} + + + {gettext("View on MusicBrainz")} + + + <.link + class="block px-3 py-1 text-sm leading-6 text-zinc-900 dark:text-zinc-400 hover:bg-zinc-50 dark:hover:text-zinc-300 dark:hover:bg-zinc-700" + role="menuitem" + tabindex="0" + id={"actions-#{record.id}-edit"} + patch={@record_edit_path.(record)} + > + {gettext("Edit")} + + + <.link + :if={!record.purchased_at} + class="block px-3 py-1 text-sm leading-6 text-zinc-900 dark:text-zinc-400 hover:bg-zinc-50 dark:hover:text-zinc-300 dark:hover:bg-zinc-700" + role="menuitem" + tabindex="0" + id={"actions-#{record.id}-purchase"} + phx-click={ + JS.dispatch("music_library:confetti") + |> JS.push("add-to-collection", value: %{id: record.id}) + } + > + {gettext("Purchased")} + + + <.link + class="block px-3 py-1 text-sm leading-6 text-red-900 hover:bg-red-50 dark:text-red-700 dark:hover:bg-red-900/30 dark:hover:text-red-600" + role="menuitem" + tabindex="0" + id={"actions-#{record.id}-delete"} + phx-click={JS.push("delete", value: %{id: record.id}) |> hide("##{id}")} + data-confirm={gettext("Are you sure?")} + > + {gettext("Delete")} + + +
+

{format_label(record.format)} ยท {type_label(record.type)}

diff --git a/lib/music_library_web/live/artist_live/show.html.heex b/lib/music_library_web/live/artist_live/show.html.heex index ba8f7d44..0644cd47 100644 --- a/lib/music_library_web/live/artist_live/show.html.heex +++ b/lib/music_library_web/live/artist_live/show.html.heex @@ -176,7 +176,8 @@ id="collection" records={@streams.collection_records} records_count={@collection_records_count} - record_path={fn record -> ~p"/collection/#{record}" end} + record_show_path={fn record -> ~p"/collection/#{record}" end} + record_edit_path={fn record -> ~p"/collection/#{record}/show/edit" end} /> <.separator :if={@wishlist_records_count > 0} class="mt-8 mb-8" /> <.record_grid @@ -185,7 +186,8 @@ id="wishlist" records={@streams.wishlist_records} records_count={@wishlist_records_count} - record_path={fn record -> ~p"/wishlist/#{record}" end} + record_show_path={fn record -> ~p"/wishlist/#{record}" end} + record_edit_path={fn record -> ~p"/wishlist/#{record}/show/edit" end} /> <.async_result :let={similar_artists} assign={@similar_artists}>