Show artist MusicBrainz ID (with link and copy button)

This commit is contained in:
Claudio Ortolina
2025-05-15 16:59:12 +01:00
parent f754d631f2
commit cc3cf02490
5 changed files with 37 additions and 4 deletions
+4
View File
@@ -19,6 +19,10 @@ defmodule MusicBrainz.Artist do
end) end)
end end
def url(id) do
"https://musicbrainz.org/artist/#{id}"
end
defp parse_relations(relations) do defp parse_relations(relations) do
Enum.map(relations, fn relation -> Enum.map(relations, fn relation ->
%{ %{
@@ -50,8 +50,8 @@
</div> </div>
</header> </header>
<div class="mt-4 grid md:grid-cols-5 md:gap-4"> <div class="mt-4 grid md:grid-cols-10 md:gap-4">
<div class="col-span-5 md:col-span-1 mt-4 order-2 md:order-1"> <div class="md:col-span-3 mt-4 order-2 md:order-1">
<h2 class="font-semibold text-base sm:text-lg leading-5 text-zinc-700 dark:text-zinc-300"> <h2 class="font-semibold text-base sm:text-lg leading-5 text-zinc-700 dark:text-zinc-300">
{gettext("Meta")} {gettext("Meta")}
</h2> </h2>
@@ -61,6 +61,30 @@
alt={@artist.name} alt={@artist.name}
onerror={"this.src = '" <> ~p"/images/cover-not-found.png" <> "';"} onerror={"this.src = '" <> ~p"/images/cover-not-found.png" <> "';"}
/> />
<dl>
<dt class="mt-4 text-sm">
{gettext("MusicBrainz ID")}
</dt>
<dd class="mt-2 text-sm flex justify-between">
<a href={MusicBrainz.Artist.url(@artist.musicbrainz_id)}>
<code class="overflow-hidden text-clip" id={"mb-#{@artist.musicbrainz_id}"}>
{@artist.musicbrainz_id}
</code>
</a>
<button phx-click={
JS.dispatch("music_library:clipcopy", to: "#mb-" <> @artist.musicbrainz_id)
|> JS.transition("animate-shake")
}>
<span class="sr-only">{gettext("Copy MusicBrainz ID to clipboard")}</span>
<.icon
name="hero-clipboard-document"
class="-mt-1 h-5 w-5"
aria-hidden="true"
data-slot="icon"
/>
</button>
</dd>
</dl>
<.async_result :let={lastfm_artist_info} assign={@lastfm_artist_info}> <.async_result :let={lastfm_artist_info} assign={@lastfm_artist_info}>
<:loading> <:loading>
<div class="mt-4 text-sm leading-5 text-zinc-500 dark:text-zinc-400"> <div class="mt-4 text-sm leading-5 text-zinc-500 dark:text-zinc-400">
@@ -122,7 +146,7 @@
</details> </details>
</.async_result> </.async_result>
</div> </div>
<div class="col-span-4 md:order-1"> <div class="md:col-span-7 md:order-1">
<.record_grid <.record_grid
:if={@collection_records_count > 0} :if={@collection_records_count > 0}
title={gettext("Collection")} title={gettext("Collection")}
+2
View File
@@ -106,6 +106,7 @@ msgid "Logout"
msgstr "" msgstr ""
#: lib/music_library_web/components/form_component.ex #: lib/music_library_web/components/form_component.ex
#: lib/music_library_web/live/artist_live/show.html.heex
#: lib/music_library_web/live/collection_live/show.html.heex #: lib/music_library_web/live/collection_live/show.html.heex
#: lib/music_library_web/live/wishlist_live/show.html.heex #: lib/music_library_web/live/wishlist_live/show.html.heex
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
@@ -262,6 +263,7 @@ msgstr ""
msgid "close" msgid "close"
msgstr "" msgstr ""
#: lib/music_library_web/live/artist_live/show.html.heex
#: lib/music_library_web/live/collection_live/show.html.heex #: lib/music_library_web/live/collection_live/show.html.heex
#: lib/music_library_web/live/wishlist_live/show.html.heex #: lib/music_library_web/live/wishlist_live/show.html.heex
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
+2
View File
@@ -106,6 +106,7 @@ msgid "Logout"
msgstr "" msgstr ""
#: lib/music_library_web/components/form_component.ex #: lib/music_library_web/components/form_component.ex
#: lib/music_library_web/live/artist_live/show.html.heex
#: lib/music_library_web/live/collection_live/show.html.heex #: lib/music_library_web/live/collection_live/show.html.heex
#: lib/music_library_web/live/wishlist_live/show.html.heex #: lib/music_library_web/live/wishlist_live/show.html.heex
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
@@ -262,6 +263,7 @@ msgstr ""
msgid "close" msgid "close"
msgstr "" msgstr ""
#: lib/music_library_web/live/artist_live/show.html.heex
#: lib/music_library_web/live/collection_live/show.html.heex #: lib/music_library_web/live/collection_live/show.html.heex
#: lib/music_library_web/live/wishlist_live/show.html.heex #: lib/music_library_web/live/wishlist_live/show.html.heex
#, elixir-autogen, elixir-format #, elixir-autogen, elixir-format
@@ -70,7 +70,7 @@ defmodule MusicLibraryWeb.ArtistLive.ShowTest do
|> assert_has("div", text: "Error loading biography") |> assert_has("div", text: "Error loading biography")
end end
test "it shows the artist country", %{ test "it shows the artist country and MB id", %{
conn: conn, conn: conn,
artist_musicbrainz_id: artist_musicbrainz_id artist_musicbrainz_id: artist_musicbrainz_id
} do } do
@@ -89,6 +89,7 @@ defmodule MusicLibraryWeb.ArtistLive.ShowTest do
|> unwrap(&render_async/1) |> unwrap(&render_async/1)
|> assert_has("span", text: "United Kingdom") |> assert_has("span", text: "United Kingdom")
|> assert_has("span", text: "🇬🇧") |> assert_has("span", text: "🇬🇧")
|> assert_has("dd", text: artist_musicbrainz_id)
end end
test "it shows records from the collection and the wishlist", %{ test "it shows records from the collection and the wishlist", %{