From 5babccfeb87238505ae75c0d4bccc5866ce10587 Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Fri, 15 Nov 2024 10:03:45 +0000 Subject: [PATCH] Can refresh data for wishlist records --- .../live/wishlist_live/show.ex | 20 ++++++++++++++ .../live/wishlist_live/show.html.heex | 5 ++++ priv/gettext/default.pot | 27 ++++++++++--------- 3 files changed, 40 insertions(+), 12 deletions(-) diff --git a/lib/music_library_web/live/wishlist_live/show.ex b/lib/music_library_web/live/wishlist_live/show.ex index 7fc5e119..fa87a35c 100644 --- a/lib/music_library_web/live/wishlist_live/show.ex +++ b/lib/music_library_web/live/wishlist_live/show.ex @@ -41,6 +41,26 @@ defmodule MusicLibraryWeb.WishlistLive.Show do {:noreply, push_navigate(socket, to: ~p"/wishlist")} 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)} diff --git a/lib/music_library_web/live/wishlist_live/show.html.heex b/lib/music_library_web/live/wishlist_live/show.html.heex index 51c52dc3..bf036989 100644 --- a/lib/music_library_web/live/wishlist_live/show.html.heex +++ b/lib/music_library_web/live/wishlist_live/show.html.heex @@ -4,6 +4,11 @@ <%= gettext("Edit") %> + <.link phx-click={JS.push("refresh_musicbrainz_data", value: %{id: @record.id})}> + <.button> + <%= gettext("Refresh MB Data") %> + + <.link phx-click={JS.push("delete", value: %{id: @record.id})} data-confirm={gettext("Are you sure?")} diff --git a/priv/gettext/default.pot b/priv/gettext/default.pot index ea3b8494..13a10a27 100644 --- a/priv/gettext/default.pot +++ b/priv/gettext/default.pot @@ -19,7 +19,7 @@ msgstr "" #: lib/music_library_web/live/record_live/index.html.heex:185 #: lib/music_library_web/live/record_live/show.html.heex:14 #: lib/music_library_web/live/wishlist_live/index.html.heex:195 -#: lib/music_library_web/live/wishlist_live/show.html.heex:9 +#: lib/music_library_web/live/wishlist_live/show.html.heex:14 #, elixir-autogen, elixir-format msgid "Are you sure?" msgstr "" @@ -34,7 +34,7 @@ msgstr "" msgid "Back to records" msgstr "" -#: lib/music_library_web/live/wishlist_live/show.html.heex:120 +#: lib/music_library_web/live/wishlist_live/show.html.heex:125 #, elixir-autogen, elixir-format msgid "Back to wishlist" msgstr "" @@ -64,7 +64,7 @@ msgstr "" #: lib/music_library_web/live/record_live/index.html.heex:187 #: lib/music_library_web/live/record_live/show.html.heex:17 #: lib/music_library_web/live/wishlist_live/index.html.heex:197 -#: lib/music_library_web/live/wishlist_live/show.html.heex:12 +#: lib/music_library_web/live/wishlist_live/show.html.heex:17 #, elixir-autogen, elixir-format msgid "Delete" msgstr "" @@ -75,7 +75,7 @@ msgstr "" #: lib/music_library_web/live/record_live/show.html.heex:4 #: lib/music_library_web/live/wishlist_live/index.ex:55 #: lib/music_library_web/live/wishlist_live/index.html.heex:176 -#: lib/music_library_web/live/wishlist_live/show.ex:50 +#: lib/music_library_web/live/wishlist_live/show.ex:70 #: lib/music_library_web/live/wishlist_live/show.html.heex:4 #, elixir-autogen, elixir-format msgid "Edit" @@ -106,7 +106,7 @@ msgid "Formats" msgstr "" #: lib/music_library_web/live/record_live/show.html.heex:54 -#: lib/music_library_web/live/wishlist_live/show.html.heex:50 +#: lib/music_library_web/live/wishlist_live/show.html.heex:55 #, elixir-autogen, elixir-format msgid "Genres" msgstr "" @@ -129,7 +129,7 @@ msgid "Import from MusicBrainz" msgstr "" #: lib/music_library_web/live/record_live/show.html.heex:107 -#: lib/music_library_web/live/wishlist_live/show.html.heex:95 +#: lib/music_library_web/live/wishlist_live/show.html.heex:100 #, elixir-autogen, elixir-format msgid "Inserted at" msgstr "" @@ -155,7 +155,7 @@ msgid "Logout" msgstr "" #: lib/music_library_web/live/record_live/show.html.heex:62 -#: lib/music_library_web/live/wishlist_live/show.html.heex:58 +#: lib/music_library_web/live/wishlist_live/show.html.heex:63 #, elixir-autogen, elixir-format msgid "MusicBrainz ID" msgstr "" @@ -256,7 +256,7 @@ msgstr "" #: lib/music_library_web/live/record_live/index.html.heex:156 #: lib/music_library_web/live/record_live/show.ex:71 #: lib/music_library_web/live/wishlist_live/index.html.heex:156 -#: lib/music_library_web/live/wishlist_live/show.ex:49 +#: lib/music_library_web/live/wishlist_live/show.ex:69 #, elixir-autogen, elixir-format msgid "Show" msgstr "" @@ -312,7 +312,7 @@ msgid "Types" msgstr "" #: lib/music_library_web/live/record_live/show.html.heex:115 -#: lib/music_library_web/live/wishlist_live/show.html.heex:103 +#: lib/music_library_web/live/wishlist_live/show.html.heex:108 #, elixir-autogen, elixir-format msgid "Updated at" msgstr "" @@ -351,13 +351,13 @@ msgid "close" msgstr "" #: lib/music_library_web/live/record_live/show.html.heex:72 -#: lib/music_library_web/live/wishlist_live/show.html.heex:68 +#: lib/music_library_web/live/wishlist_live/show.html.heex:73 #, elixir-autogen, elixir-format msgid "Copy MusicBrainz ID to clipboard" msgstr "" #: lib/music_library_web/live/record_live/show.html.heex:126 -#: lib/music_library_web/live/wishlist_live/show.html.heex:114 +#: lib/music_library_web/live/wishlist_live/show.html.heex:119 #, elixir-autogen, elixir-format msgid "MusicBrainz data" msgstr "" @@ -391,22 +391,25 @@ msgid "Number of included records" msgstr "" #: lib/music_library_web/live/record_live/show.html.heex:95 -#: lib/music_library_web/live/wishlist_live/show.html.heex:83 +#: lib/music_library_web/live/wishlist_live/show.html.heex:88 #, elixir-autogen, elixir-format msgid "Includes" msgstr "" #: lib/music_library_web/live/record_live/show.ex:61 +#: lib/music_library_web/live/wishlist_live/show.ex:59 #, elixir-autogen, elixir-format msgid "Error refreshing MusicBrainz data" msgstr "" #: lib/music_library_web/live/record_live/show.ex:53 +#: lib/music_library_web/live/wishlist_live/show.ex:51 #, elixir-autogen, elixir-format msgid "MusicBrainz data refreshed successfully" msgstr "" #: lib/music_library_web/live/record_live/show.html.heex:9 +#: lib/music_library_web/live/wishlist_live/show.html.heex:9 #, elixir-autogen, elixir-format msgid "Refresh MB Data" msgstr ""