Can scrobble a release from the UI

This commit is contained in:
Claudio Ortolina
2025-05-07 09:38:09 +01:00
parent a94c349781
commit fa66db8258
3 changed files with 43 additions and 3 deletions
@@ -11,7 +11,7 @@ defmodule MusicLibraryWeb.CollectionLive.Show do
format_duration: 1
]
alias MusicLibrary.Records
alias MusicLibrary.{Records, ScrobbleActivity}
alias Phoenix.LiveView.JS
@impl true
@@ -128,6 +128,29 @@ defmodule MusicLibraryWeb.CollectionLive.Show do
end)}
end
def handle_event("scrobble_release", _params, socket) do
release_with_tracks_async_result =
socket.assigns.release_with_tracks
if release_with_tracks =
release_with_tracks_async_result && release_with_tracks_async_result.result do
case ScrobbleActivity.scrobble(release_with_tracks, DateTime.utc_now()) do
{:ok, _} ->
{:noreply,
socket
|> put_flash(:info, gettext("Release scrobbled successfully"))}
{:error, reason} ->
{:noreply,
socket
|> put_flash(
:error,
gettext("Error scrobbling release") <> "," <> inspect(reason)
)}
end
end
end
@impl true
def handle_info({MusicLibraryWeb.FormComponent, {:saved, record}}, socket) do
{:noreply, assign(socket, :record, record)}
@@ -280,9 +280,11 @@
placement="right"
on_open={JS.push("load_release_with_tracks")}
>
<h3 class="text-lg font-semibold text-zinc-700 dark:text-zinc-300 mb-4">{gettext("Tracks")}</h3>
<h3 class="text-lg font-semibold text-zinc-700 dark:text-zinc-300">{gettext("Tracks")}</h3>
<div :if={@release_with_tracks} class="space-y-4">
<.button phx-click="scrobble_release">{gettext("Scrobble to Last.fm")}</.button>
<div :if={@release_with_tracks} class="space-y-4 mt-4">
<.async_result :let={release_with_tracks} assign={@release_with_tracks}>
<:loading>
<span class="sr-only">{gettext("Loading release with tracks")}</span>
+15
View File
@@ -784,3 +784,18 @@ msgstr ""
#, elixir-autogen, elixir-format
msgid "Successfully connected your Last.fm account"
msgstr ""
#: lib/music_library_web/live/collection_live/show.ex
#, elixir-autogen, elixir-format
msgid "Error scrobbling release"
msgstr ""
#: lib/music_library_web/live/collection_live/show.ex
#, elixir-autogen, elixir-format
msgid "Release scrobbled successfully"
msgstr ""
#: lib/music_library_web/live/collection_live/show.html.heex
#, elixir-autogen, elixir-format
msgid "Scrobble to Last.fm"
msgstr ""