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") %>
+25 -14
View File
@@ -17,7 +17,7 @@ msgid "Actions"
msgstr ""
#: lib/music_library_web/live/record_live/index.html.heex:185
#: lib/music_library_web/live/record_live/show.html.heex:42
#: lib/music_library_web/live/record_live/show.html.heex:47
#: lib/music_library_web/live/wishlist_live/index.html.heex:195
#: lib/music_library_web/live/wishlist_live/show.html.heex:42
#, elixir-autogen, elixir-format
@@ -29,7 +29,7 @@ msgstr ""
msgid "Attempting to reconnect"
msgstr ""
#: lib/music_library_web/live/record_live/show.html.heex:135
#: lib/music_library_web/live/record_live/show.html.heex:140
#, elixir-autogen, elixir-format
msgid "Back to records"
msgstr ""
@@ -62,7 +62,7 @@ msgid "Cover art"
msgstr ""
#: lib/music_library_web/live/record_live/index.html.heex:187
#: lib/music_library_web/live/record_live/show.html.heex:48
#: lib/music_library_web/live/record_live/show.html.heex:53
#: lib/music_library_web/live/wishlist_live/index.html.heex:197
#: lib/music_library_web/live/wishlist_live/show.html.heex:48
#, elixir-autogen, elixir-format
@@ -71,7 +71,7 @@ msgstr ""
#: lib/music_library_web/live/record_live/index.ex:55
#: lib/music_library_web/live/record_live/index.html.heex:176
#: lib/music_library_web/live/record_live/show.ex:72
#: lib/music_library_web/live/record_live/show.ex:92
#: lib/music_library_web/live/record_live/show.html.heex:32
#: lib/music_library_web/live/wishlist_live/index.ex:55
#: lib/music_library_web/live/wishlist_live/index.html.heex:176
@@ -105,7 +105,7 @@ msgstr ""
msgid "Formats"
msgstr ""
#: lib/music_library_web/live/record_live/show.html.heex:57
#: lib/music_library_web/live/record_live/show.html.heex:62
#: lib/music_library_web/live/wishlist_live/show.html.heex:58
#, elixir-autogen, elixir-format
msgid "Genres"
@@ -128,7 +128,7 @@ msgstr ""
msgid "Import from MusicBrainz"
msgstr ""
#: lib/music_library_web/live/record_live/show.html.heex:110
#: lib/music_library_web/live/record_live/show.html.heex:115
#: lib/music_library_web/live/wishlist_live/show.html.heex:103
#, elixir-autogen, elixir-format
msgid "Inserted at"
@@ -155,7 +155,7 @@ msgid "Logout"
msgstr ""
#: lib/music_library_web/live/record_live/form_component.ex:46
#: lib/music_library_web/live/record_live/show.html.heex:65
#: lib/music_library_web/live/record_live/show.html.heex:70
#: lib/music_library_web/live/wishlist_live/show.html.heex:66
#, elixir-autogen, elixir-format
msgid "MusicBrainz ID"
@@ -205,7 +205,7 @@ msgstr ""
msgid "Purchased at"
msgstr ""
#: lib/music_library_web/live/record_live/show.html.heex:87
#: lib/music_library_web/live/record_live/show.html.heex:92
#, elixir-autogen, elixir-format
msgid "Purchased on"
msgstr ""
@@ -255,7 +255,7 @@ msgid "Search for records"
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/record_live/show.ex:91
#: lib/music_library_web/live/wishlist_live/index.html.heex:156
#: lib/music_library_web/live/wishlist_live/show.ex:69
#, elixir-autogen, elixir-format
@@ -312,7 +312,7 @@ msgstr ""
msgid "Types"
msgstr ""
#: lib/music_library_web/live/record_live/show.html.heex:118
#: lib/music_library_web/live/record_live/show.html.heex:123
#: lib/music_library_web/live/wishlist_live/show.html.heex:111
#, elixir-autogen, elixir-format
msgid "Updated at"
@@ -351,13 +351,13 @@ msgstr ""
msgid "close"
msgstr ""
#: lib/music_library_web/live/record_live/show.html.heex:75
#: lib/music_library_web/live/record_live/show.html.heex:80
#: lib/music_library_web/live/wishlist_live/show.html.heex:76
#, elixir-autogen, elixir-format
msgid "Copy MusicBrainz ID to clipboard"
msgstr ""
#: lib/music_library_web/live/record_live/show.html.heex:129
#: lib/music_library_web/live/record_live/show.html.heex:134
#: lib/music_library_web/live/wishlist_live/show.html.heex:122
#, elixir-autogen, elixir-format
msgid "MusicBrainz data"
@@ -391,13 +391,14 @@ msgstr ""
msgid "Number of included records"
msgstr ""
#: lib/music_library_web/live/record_live/show.html.heex:98
#: lib/music_library_web/live/record_live/show.html.heex:103
#: lib/music_library_web/live/wishlist_live/show.html.heex:91
#, elixir-autogen, elixir-format
msgid "Includes"
msgstr ""
#: lib/music_library_web/live/record_live/show.ex:61
#: lib/music_library_web/live/record_live/show.ex:81
#: lib/music_library_web/live/wishlist_live/show.ex:59
#, elixir-autogen, elixir-format
msgid "Error refreshing MusicBrainz data"
@@ -409,7 +410,7 @@ msgstr ""
msgid "MusicBrainz data refreshed successfully"
msgstr ""
#: lib/music_library_web/live/record_live/show.html.heex:37
#: lib/music_library_web/live/record_live/show.html.heex:42
#: lib/music_library_web/live/wishlist_live/show.html.heex:37
#, elixir-autogen, elixir-format
msgid "Refresh MB Data"
@@ -419,3 +420,13 @@ msgstr ""
#, elixir-autogen, elixir-format
msgid "Refresh LastFm Feed"
msgstr ""
#: lib/music_library_web/live/record_live/show.ex:73
#, elixir-autogen, elixir-format
msgid "Cover refreshed successfully"
msgstr ""
#: lib/music_library_web/live/record_live/show.html.heex:37
#, elixir-autogen, elixir-format
msgid "Refresh Cover"
msgstr ""
+1 -1
View File
@@ -290,7 +290,7 @@ defmodule MusicLibrary.RecordsTest do
{:ok, raven_cover_data}
end)
updated_record = Records.refresh_cover(record)
assert {:ok, updated_record} = Records.refresh_cover(record)
assert updated_record.cover_data !== record.cover_data