Can refresh artist info and image from UI

This commit is contained in:
Claudio Ortolina
2025-05-20 09:41:44 +01:00
parent eb064a65a5
commit ee27b7a252
4 changed files with 167 additions and 5 deletions
+39 -1
View File
@@ -3,7 +3,9 @@ defmodule MusicLibraryWeb.ArtistLive.Show do
alias MusicLibrary.{Artists, Records}
alias MusicLibrary.Records.ArtistInfo
import MusicLibraryWeb.RecordComponents, only: [record_grid: 1]
import MusicLibraryWeb.RecordComponents,
only: [record_grid: 1, toggle_actions_menu: 1, close_actions_menu: 1]
attr :country, :map, required: true
@@ -81,6 +83,42 @@ defmodule MusicLibraryWeb.ArtistLive.Show do
end
end
def handle_event("refresh_artist_info", %{"id" => id}, socket) do
case Artists.fetch_artist_info(id) do
{:ok, artist_info} ->
{:noreply,
socket
|> assign(:artist_info, artist_info)
|> put_flash(:info, gettext("Artist info refreshed successfully"))}
{:error, reason} ->
{:noreply,
socket
|> put_flash(
:error,
gettext("Error refreshing artist info") <> "," <> inspect(reason)
)}
end
end
def handle_event("refresh_artist_image", %{"id" => id}, socket) do
case Artists.fetch_image(id) do
{:ok, artist_info} ->
{:noreply,
socket
|> assign(:artist_info, artist_info)
|> put_flash(:info, gettext("Artist image refreshed successfully"))}
{:error, reason} ->
{:noreply,
socket
|> put_flash(
:error,
gettext("Error refreshing artist image") <> "," <> inspect(reason)
)}
end
end
defp apply_action(socket, :show, %{"musicbrainz_id" => musicbrainz_id}) do
artist = Artists.get_artist!(musicbrainz_id)
artist_info = Artists.get_artist_info!(musicbrainz_id)