Allow scrobbling wishlisted records

This commit is contained in:
Claudio Ortolina
2026-05-29 08:09:55 +03:00
parent dd24258f33
commit 33474c1472
4 changed files with 84 additions and 0 deletions
@@ -58,6 +58,19 @@ defmodule MusicLibraryWeb.WishlistLive.Show do
/>
<span :if={@chat_count > 0} class="text-xs font-medium">{@chat_count}</span>
</.button>
<.button
:if={@record.selected_release_id}
variant="soft"
phx-click={MusicLibraryWeb.Components.Release.open("release-with-tracks-sheet")}
>
<span class="sr-only">{gettext("Show Tracks")}</span>
<.icon
name="hero-numbered-list"
class="icon"
aria-hidden="true"
data-slot="icon"
/>
</.button>
<.dropdown id={"actions-#{@record.id}"} placement="bottom-end">
<:toggle>
<.button variant="soft">
@@ -252,6 +265,22 @@ defmodule MusicLibraryWeb.WishlistLive.Show do
<.record_debug_sheet record={@record} embedding_text={@embedding_text} />
<.sheet
:if={@record.selected_release_id}
id="release-with-tracks-sheet"
placement="right"
class="flex min-w-xs flex-col overflow-hidden p-0 sm:min-w-sm"
>
<.live_component
id="release-with-tracks"
sheet_id="release-with-tracks-sheet"
module={MusicLibraryWeb.Components.Release}
release_id={@record.selected_release_id}
show_print?={false}
timezone={@timezone}
/>
</.sheet>
<.live_component
id="record-chat"
sheet_id="record-chat-sheet"
@@ -363,6 +392,10 @@ defmodule MusicLibraryWeb.WishlistLive.Show do
RecordActions.handle_chats_changed(socket)
end
def handle_info({MusicLibraryWeb.Components.Release, {:loaded, _release}}, socket) do
{:noreply, socket}
end
@impl true
def handle_info({:update, record}, socket) do
cond do
+1
View File
@@ -623,6 +623,7 @@ msgid "Loading release with tracks"
msgstr ""
#: lib/music_library_web/live/collection_live/show.ex
#: lib/music_library_web/live/wishlist_live/show.ex
#, elixir-autogen, elixir-format
msgid "Show Tracks"
msgstr ""
+1
View File
@@ -623,6 +623,7 @@ msgid "Loading release with tracks"
msgstr ""
#: lib/music_library_web/live/collection_live/show.ex
#: lib/music_library_web/live/wishlist_live/show.ex
#, elixir-autogen, elixir-format
msgid "Show Tracks"
msgstr ""
@@ -4,12 +4,25 @@ defmodule MusicLibraryWeb.WishlistLive.ShowTest do
import MusicLibrary.Fixtures.Records
import MusicLibraryWeb.RecordComponents, only: [format_label: 1, type_label: 1]
alias MusicBrainz.Fixtures
alias MusicLibrary.Assets.Transform
alias MusicLibrary.Records
alias MusicLibrary.Records.Record
alias Phoenix.PubSub
defp stub_release(_) do
release_response = Fixtures.Release.release(:marbles)
Req.Test.stub(MusicBrainz.API, fn conn ->
Req.Test.json(conn, release_response)
end)
%{release_response: release_response}
end
describe "Edit record from show page" do
setup [:stub_release]
test "can navigate to the record edit form", %{conn: conn} do
record = record(purchased_at: nil)
@@ -22,6 +35,8 @@ defmodule MusicLibraryWeb.WishlistLive.ShowTest do
end
describe "Show record" do
setup [:stub_release]
test "includes all needed information", %{conn: conn} do
record = record(purchased_at: nil)
transform = %Transform{hash: record.cover_hash, width: nil}
@@ -55,6 +70,8 @@ defmodule MusicLibraryWeb.WishlistLive.ShowTest do
end
describe "Delete record" do
setup [:stub_release]
test "deletes the record and navigates back to wishlist", %{conn: conn} do
record = record(purchased_at: nil)
@@ -70,6 +87,8 @@ defmodule MusicLibraryWeb.WishlistLive.ShowTest do
end
describe "handle_info({:update, record}) with live_action guard" do
setup [:stub_release]
test "updates record when showing (live_action is :show)", %{conn: conn} do
record = record(purchased_at: nil)
updated_record = %{record | title: "Background Updated Title"}
@@ -132,4 +151,34 @@ defmodule MusicLibraryWeb.WishlistLive.ShowTest do
|> refute_has("#toast-group", text: "Record updated in the background")
end
end
describe "Side panel" do
setup [:stub_release]
test "shows a record's tracks", %{conn: conn, release_response: release_response} do
record = record()
session =
conn
|> visit(~p"/wishlist/#{record.id}")
|> assert_has("button", "Show Tracks")
|> render_async()
|> assert_has("a", "Connect Last.fm")
release =
MusicBrainz.Release.from_api_response(release_response)
for medium <- release.media do
session
|> within("#disc-#{medium.number}", fn inner_session ->
for track <- medium.tracks do
inner_session
|> assert_has("li", escape(track.title))
end
inner_session
end)
end
end
end
end