Can refresh cover for a record in the collection

This commit is contained in:
Claudio Ortolina
2024-11-19 11:25:11 +00:00
parent cc1d2e3b0f
commit 09f3563134
5 changed files with 52 additions and 16 deletions
+1 -1
View File
@@ -131,7 +131,7 @@ defmodule MusicLibrary.Records do
record
|> Record.add_cover_data(thumb_data)
|> Repo.update!()
|> Repo.update()
end
end
@@ -63,6 +63,26 @@ defmodule MusicLibraryWeb.RecordLive.Show do
end
end
def handle_event("refresh_cover", %{"id" => id}, socket) do
record = Records.get_record!(id)
case Records.refresh_cover(record) do
{:ok, updated_record} ->
{:noreply,
socket
|> put_flash(:info, gettext("Cover 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)}
@@ -32,6 +32,11 @@
<%= gettext("Edit") %>
</.button>
</.link>
<.link phx-click={JS.push("refresh_cover", value: %{id: @record.id})}>
<.button type="button" class="relative -ml-px inline-flex items-center rounded-none">
<%= gettext("Refresh Cover") %>
</.button>
</.link>
<.link phx-click={JS.push("refresh_musicbrainz_data", value: %{id: @record.id})}>
<.button type="button" class="relative -ml-px inline-flex items-center rounded-none">
<%= gettext("Refresh MB Data") %>