From c705517415a1b33e5edaf736bfd0260323d5f486 Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Sat, 14 Dec 2024 17:23:59 +0300 Subject: [PATCH] Restore import functionality from stats Accidentally removed in 135d1c2. --- .../live/stats_live/index.ex | 26 +++++++++++++++++++ priv/gettext/default.pot | 3 +++ 2 files changed, 29 insertions(+) diff --git a/lib/music_library_web/live/stats_live/index.ex b/lib/music_library_web/live/stats_live/index.ex index d4a02384..70937982 100644 --- a/lib/music_library_web/live/stats_live/index.ex +++ b/lib/music_library_web/live/stats_live/index.ex @@ -56,6 +56,32 @@ defmodule MusicLibraryWeb.StatsLive.Index do {:noreply, socket} end + def handle_event("import", %{"id" => musicbrainz_id, "format" => format}, socket) do + case Records.import_from_musicbrainz_release(musicbrainz_id, + format: format, + purchased_at: nil + ) do + {:ok, record} -> + {:noreply, + socket + |> put_flash(:info, gettext("Record imported successfully")) + |> push_navigate(to: ~p"/wishlist/#{record.id}")} + + {:error, %Ecto.Changeset{} = changeset} -> + {:noreply, + socket + |> put_flash( + :error, + gettext("Error importing record") <> "," <> inspect(changeset.errors) + )} + + {:error, reason} -> + {:noreply, + socket + |> put_flash(:error, gettext("Error importing record") <> "," <> inspect(reason))} + end + end + def handle_info(%{tracks: recent_tracks}, socket) do release_ids = release_ids(recent_tracks) diff --git a/priv/gettext/default.pot b/priv/gettext/default.pot index 073b085c..6b158b5e 100644 --- a/priv/gettext/default.pot +++ b/priv/gettext/default.pot @@ -81,6 +81,8 @@ msgstr "" #: lib/music_library_web/live/collection_live/index.ex:124 #: lib/music_library_web/live/collection_live/index.ex:131 +#: lib/music_library_web/live/stats_live/index.ex:75 +#: lib/music_library_web/live/stats_live/index.ex:81 #: lib/music_library_web/live/wishlist_live/index.ex:121 #: lib/music_library_web/live/wishlist_live/index.ex:128 #, elixir-autogen, elixir-format @@ -204,6 +206,7 @@ msgid "Purchased on" msgstr "" #: lib/music_library_web/live/collection_live/index.ex:116 +#: lib/music_library_web/live/stats_live/index.ex:67 #: lib/music_library_web/live/wishlist_live/index.ex:113 #, elixir-autogen, elixir-format msgid "Record imported successfully"