diff --git a/lib/music_library_web/live/collection_live/show.ex b/lib/music_library_web/live/collection_live/show.ex index c243a978..faa0ace6 100644 --- a/lib/music_library_web/live/collection_live/show.ex +++ b/lib/music_library_web/live/collection_live/show.ex @@ -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)} diff --git a/lib/music_library_web/live/collection_live/show.html.heex b/lib/music_library_web/live/collection_live/show.html.heex index 9619f966..1c61a0a9 100644 --- a/lib/music_library_web/live/collection_live/show.html.heex +++ b/lib/music_library_web/live/collection_live/show.html.heex @@ -280,9 +280,11 @@ placement="right" on_open={JS.push("load_release_with_tracks")} > -