Can refresh musicbrainz_data for collection records

This commit is contained in:
Claudio Ortolina
2024-11-15 10:01:53 +00:00
parent ac6b398afc
commit 60b098785b
4 changed files with 61 additions and 13 deletions
@@ -43,6 +43,26 @@ defmodule MusicLibraryWeb.RecordLive.Show do
{:noreply, push_navigate(socket, to: ~p"/records")}
end
def handle_event("refresh_musicbrainz_data", %{"id" => id}, socket) do
record = Records.get_record!(id)
case Records.refresh_musicbrainz_data(record) do
{:ok, updated_record} ->
{:noreply,
socket
|> put_flash(:info, gettext("MusicBrainz data refreshed successfully"))
|> assign(:record, updated_record)}
{:error, reason} ->
{:noreply,
socket
|> put_flash(
:error,
gettext("Error refreshing MusicBrainz data") <> "," <> inspect(reason)
)}
end
end
@impl true
def handle_info({MusicLibraryWeb.RecordLive.FormComponent, {:saved, record}}, socket) do
{:noreply, assign(socket, :record, record)}
@@ -4,6 +4,11 @@
<%= gettext("Edit") %>
</.button>
</.link>
<.link phx-click={JS.push("refresh_musicbrainz_data", value: %{id: @record.id})}>
<.button>
<%= gettext("Refresh MB Data") %>
</.button>
</.link>
<.link
phx-click={JS.push("delete", value: %{id: @record.id})}
data-confirm={gettext("Are you sure?")}