diff --git a/lib/music_library_web/live/collection_live/show.ex b/lib/music_library_web/live/collection_live/show.ex
index da4150fb..507fb298 100644
--- a/lib/music_library_web/live/collection_live/show.ex
+++ b/lib/music_library_web/live/collection_live/show.ex
@@ -1,6 +1,8 @@
defmodule MusicLibraryWeb.CollectionLive.Show do
use MusicLibraryWeb, :live_view
+ require Logger
+
import MusicLibrary.ListeningStats, only: [localize_scrobbled_at: 2]
import MusicLibraryWeb.RecordComponents,
@@ -24,6 +26,8 @@ defmodule MusicLibraryWeb.CollectionLive.Show do
alias MusicLibraryWeb.ErrorMessages
alias Phoenix.LiveView.JS
+ alias MusicBrainz
+
@impl true
def render(assigns) do
~H"""
@@ -44,12 +48,13 @@ defmodule MusicLibraryWeb.CollectionLive.Show do
<.button_group>
<.button
+ :if={@can_scrobble? and @record.selected_release_id}
variant="soft"
- phx-click={MusicLibraryWeb.Components.Notes.open("record-notes-sheet")}
+ phx-click="scrobble_release"
>
- {gettext("Open Notes")}
+ {gettext("Scrobble release")}
<.icon
- name="hero-pencil"
+ name="hero-play"
class="h-5 w-5"
aria-hidden="true"
data-slot="icon"
@@ -80,18 +85,6 @@ defmodule MusicLibraryWeb.CollectionLive.Show do
data-slot="icon"
/>
- <.button
- variant="soft"
- phx-click={Fluxon.open_dialog("debug-data")}
- >
- {gettext("Debug data")}
- <.icon
- name="hero-code-bracket"
- class="h-5 w-5"
- aria-hidden="true"
- data-slot="icon"
- />
-
<.dropdown id={"actions-#{@record.id}"} placement="bottom-end">
<:toggle>
<.button variant="soft">
@@ -105,6 +98,34 @@ defmodule MusicLibraryWeb.CollectionLive.Show do
<.focus_wrap id={"actions-#{@record.id}-focus-wrap"}>
+ <.dropdown_link
+ id={"actions-#{@record.id}-notes"}
+ phx-click={MusicLibraryWeb.Components.Notes.open("record-notes-sheet")}
+ >
+ <.icon
+ name="hero-pencil"
+ class="h-4 w-4 mr-1"
+ aria-hidden="true"
+ data-slot="icon"
+ />
+ {gettext("Notes")}
+
+
+ <.dropdown_link
+ id={"actions-#{@record.id}-debug"}
+ phx-click={Fluxon.open_dialog("debug-data")}
+ >
+ <.icon
+ name="hero-code-bracket"
+ class="h-4 w-4 mr-1"
+ aria-hidden="true"
+ data-slot="icon"
+ />
+ {gettext("Debug data")}
+
+
+ <.dropdown_separator />
+
<.dropdown_link
id={"actions-#{@record.id}-edit"}
patch={~p"/collection/#{@record}/show/edit"}
@@ -455,6 +476,46 @@ defmodule MusicLibraryWeb.CollectionLive.Show do
end
end
+ def handle_event("scrobble_release", _params, socket) do
+ record = socket.assigns.record
+
+ {:noreply,
+ start_async(socket, :scrobble_release, fn ->
+ with {:ok, release} <- MusicBrainz.get_release(record.selected_release_id) do
+ release_with_tracks = MusicBrainz.Release.from_api_response(release)
+
+ ScrobbleActivity.scrobble_release(release_with_tracks,
+ finished_at: DateTime.utc_now()
+ )
+ end
+ end)}
+ end
+
+ @impl true
+ def handle_async(:scrobble_release, {:ok, {:ok, _result}}, socket) do
+ {:noreply, put_toast(socket, :info, gettext("Release scrobbled successfully"))}
+ end
+
+ def handle_async(:scrobble_release, {:ok, {:error, reason}}, socket) do
+ {:noreply,
+ put_toast(
+ socket,
+ :error,
+ gettext("Error scrobbling release") <> ": " <> ErrorMessages.friendly_message(reason)
+ )}
+ end
+
+ def handle_async(:scrobble_release, {:exit, reason}, socket) do
+ Logger.error("Scrobble release failed: #{inspect(reason)}")
+
+ {:noreply,
+ put_toast(
+ socket,
+ :error,
+ gettext("Error scrobbling release") <> ": " <> ErrorMessages.friendly_message(reason)
+ )}
+ end
+
@impl true
def handle_info({MusicLibraryWeb.Components.RecordForm, {:saved, record}}, socket) do
{:noreply,
diff --git a/lib/music_library_web/live/wishlist_live/show.ex b/lib/music_library_web/live/wishlist_live/show.ex
index cf435ed2..3e13ba9d 100644
--- a/lib/music_library_web/live/wishlist_live/show.ex
+++ b/lib/music_library_web/live/wishlist_live/show.ex
@@ -52,18 +52,6 @@ defmodule MusicLibraryWeb.WishlistLive.Show do
data-slot="icon"
/>
- <.button
- variant="soft"
- phx-click={Fluxon.open_dialog("debug-data")}
- >
- {gettext("Debug data")}
- <.icon
- name="hero-code-bracket"
- class="h-5 w-5"
- aria-hidden="true"
- data-slot="icon"
- />
-
<.dropdown id={"actions-#{@record.id}"} placement="bottom-end">
<:toggle>
<.button variant="soft">
@@ -77,6 +65,21 @@ defmodule MusicLibraryWeb.WishlistLive.Show do
<.focus_wrap id={"actions-#{@record.id}-focus-wrap"}>
+ <.dropdown_link
+ id={"actions-#{@record.id}-debug"}
+ phx-click={Fluxon.open_dialog("debug-data")}
+ >
+ <.icon
+ name="hero-code-bracket"
+ class="h-4 w-4 mr-1"
+ aria-hidden="true"
+ data-slot="icon"
+ />
+ {gettext("Debug data")}
+
+
+ <.dropdown_separator />
+
<.dropdown_link
id={"actions-#{@record.id}-edit"}
patch={~p"/wishlist/#{@record}/show/edit"}
diff --git a/priv/gettext/default.pot b/priv/gettext/default.pot
index 6b2301b1..7fd89692 100644
--- a/priv/gettext/default.pot
+++ b/priv/gettext/default.pot
@@ -674,12 +674,14 @@ msgid "Successfully connected your Last.fm account"
msgstr ""
#: lib/music_library_web/components/release.ex
+#: lib/music_library_web/live/collection_live/show.ex
#: lib/music_library_web/live/scrobble_live/show.ex
#, elixir-autogen, elixir-format
msgid "Error scrobbling release"
msgstr ""
#: lib/music_library_web/components/release.ex
+#: lib/music_library_web/live/collection_live/show.ex
#: lib/music_library_web/live/scrobble_live/show.ex
#, elixir-autogen, elixir-format
msgid "Release scrobbled successfully"
@@ -697,6 +699,7 @@ msgid "Scrobbling..."
msgstr ""
#: lib/music_library_web/components/release.ex
+#: lib/music_library_web/live/collection_live/show.ex
#, elixir-autogen, elixir-format
msgid "Scrobble release"
msgstr ""
@@ -1295,7 +1298,6 @@ msgid "Note updated successfully"
msgstr ""
#: lib/music_library_web/live/artist_live/show.ex
-#: lib/music_library_web/live/collection_live/show.ex
#, elixir-autogen, elixir-format
msgid "Open Notes"
msgstr ""
@@ -2277,3 +2279,8 @@ msgstr ""
#, elixir-autogen, elixir-format
msgid "Sending..."
msgstr ""
+
+#: lib/music_library_web/live/collection_live/show.ex
+#, elixir-autogen, elixir-format
+msgid "Notes"
+msgstr ""
diff --git a/priv/gettext/en/LC_MESSAGES/default.po b/priv/gettext/en/LC_MESSAGES/default.po
index d3e852f6..8000de8c 100644
--- a/priv/gettext/en/LC_MESSAGES/default.po
+++ b/priv/gettext/en/LC_MESSAGES/default.po
@@ -674,12 +674,14 @@ msgid "Successfully connected your Last.fm account"
msgstr ""
#: lib/music_library_web/components/release.ex
+#: lib/music_library_web/live/collection_live/show.ex
#: lib/music_library_web/live/scrobble_live/show.ex
#, elixir-autogen, elixir-format
msgid "Error scrobbling release"
msgstr ""
#: lib/music_library_web/components/release.ex
+#: lib/music_library_web/live/collection_live/show.ex
#: lib/music_library_web/live/scrobble_live/show.ex
#, elixir-autogen, elixir-format
msgid "Release scrobbled successfully"
@@ -697,6 +699,7 @@ msgid "Scrobbling..."
msgstr ""
#: lib/music_library_web/components/release.ex
+#: lib/music_library_web/live/collection_live/show.ex
#, elixir-autogen, elixir-format
msgid "Scrobble release"
msgstr ""
@@ -1295,7 +1298,6 @@ msgid "Note updated successfully"
msgstr ""
#: lib/music_library_web/live/artist_live/show.ex
-#: lib/music_library_web/live/collection_live/show.ex
#, elixir-autogen, elixir-format
msgid "Open Notes"
msgstr ""
@@ -2277,3 +2279,8 @@ msgstr ""
#, elixir-autogen, elixir-format
msgid "Sending..."
msgstr ""
+
+#: lib/music_library_web/live/collection_live/show.ex
+#, elixir-autogen, elixir-format
+msgid "Notes"
+msgstr ""