Extract play_count and on_tour_link components

This commit is contained in:
Claudio Ortolina
2025-05-15 19:33:48 +01:00
parent 1484edb77f
commit 7e994389e7
4 changed files with 36 additions and 26 deletions
@@ -14,6 +14,34 @@ defmodule MusicLibraryWeb.ArtistLive.Show do
"""
end
attr :lastfm_artist_info, :map, required: true
defp on_tour_link(assigns) do
~H"""
<a
:if={@lastfm_artist_info.on_tour}
class="flex items-center"
href={LastFm.Artist.events_url(@lastfm_artist_info)}
target="_blank"
>
<.badge variant="pill" class="mr-2">{gettext("On Tour")}</.badge>
</a>
"""
end
attr :play_count, :integer, required: true
defp play_count(assigns) do
~H"""
<span :if={@play_count > 0} class="text-xs font-medium text-zinc-700 dark:text-zinc-300 grow">
{ngettext("1 scrobble", "%{count} scrobbles", @play_count)}
</span>
<span :if={@play_count == 0} class="text-xs font-medium text-zinc-700 dark:text-zinc-300 grow">
{gettext("No scrobbles")}
</span>
"""
end
@impl true
def mount(_params, _session, socket) do
{:ok, socket}
@@ -22,26 +22,8 @@
{gettext("Error loading play count")}
</div>
</:failed>
<a
:if={lastfm_artist_info.on_tour}
class="flex items-center"
href={LastFm.Artist.events_url(lastfm_artist_info)}
target="_blank"
>
<.badge variant="pill" class="mr-2">{gettext("On Tour")}</.badge>
</a>
<span
:if={lastfm_artist_info.play_count > 0}
class="text-xs font-medium text-zinc-700 dark:text-zinc-300 grow"
>
{ngettext("1 scrobble", "%{count} scrobbles", lastfm_artist_info.play_count)}
</span>
<span
:if={lastfm_artist_info.play_count == 0}
class="text-xs font-medium text-zinc-700 dark:text-zinc-300 grow"
>
{gettext("No scrobbles")}
</span>
<.on_tour_link lastfm_artist_info={lastfm_artist_info} />
<.play_count play_count={lastfm_artist_info.play_count} />
</.async_result>
<.button variant="solid" as="link" patch={~p"/artists/#{@artist.musicbrainz_id}/import"}>
<.icon name="hero-plus" class="h-4 w-4 mr-2" aria-hidden="true" data-slot="icon" />
+3 -3
View File
@@ -429,7 +429,7 @@ msgstr ""
msgid "Errors"
msgstr ""
#: lib/music_library_web/live/artist_live/show.html.heex
#: lib/music_library_web/live/artist_live/show.ex
#, elixir-autogen, elixir-format
msgid "On Tour"
msgstr ""
@@ -441,7 +441,7 @@ msgid_plural "%{count} records"
msgstr[0] ""
msgstr[1] ""
#: lib/music_library_web/live/artist_live/show.html.heex
#: lib/music_library_web/live/artist_live/show.ex
#, elixir-autogen, elixir-format
msgid "1 scrobble"
msgid_plural "%{count} scrobbles"
@@ -692,7 +692,7 @@ msgstr ""
msgid "Record wishlisted successfully"
msgstr ""
#: lib/music_library_web/live/artist_live/show.html.heex
#: lib/music_library_web/live/artist_live/show.ex
#, elixir-autogen, elixir-format
msgid "No scrobbles"
msgstr ""
+3 -3
View File
@@ -429,7 +429,7 @@ msgstr ""
msgid "Errors"
msgstr ""
#: lib/music_library_web/live/artist_live/show.html.heex
#: lib/music_library_web/live/artist_live/show.ex
#, elixir-autogen, elixir-format
msgid "On Tour"
msgstr ""
@@ -441,7 +441,7 @@ msgid_plural "%{count} records"
msgstr[0] ""
msgstr[1] ""
#: lib/music_library_web/live/artist_live/show.html.heex
#: lib/music_library_web/live/artist_live/show.ex
#, elixir-autogen, elixir-format
msgid "1 scrobble"
msgid_plural "%{count} scrobbles"
@@ -692,7 +692,7 @@ msgstr ""
msgid "Record wishlisted successfully"
msgstr ""
#: lib/music_library_web/live/artist_live/show.html.heex
#: lib/music_library_web/live/artist_live/show.ex
#, elixir-autogen, elixir-format
msgid "No scrobbles"
msgstr ""