Restore import functionality from stats

Accidentally removed in 135d1c2.
This commit is contained in:
Claudio Ortolina
2024-12-14 17:23:59 +03:00
parent 2fbe9db016
commit c705517415
2 changed files with 29 additions and 0 deletions
@@ -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)