Can refresh cover for a record in the wishlist

This commit is contained in:
Claudio Ortolina
2024-11-19 11:27:44 +00:00
parent 09f3563134
commit a5315e81ce
3 changed files with 41 additions and 13 deletions
@@ -61,6 +61,26 @@ defmodule MusicLibraryWeb.WishlistLive.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") %>