Fix error in rendering an artist with empty bio
Includes a refactor for a helper to test for play count
This commit is contained in:
@@ -13,7 +13,7 @@ defmodule LastFm.Artist do
|
|||||||
%__MODULE__{
|
%__MODULE__{
|
||||||
musicbrainz_id: api_response["mbid"],
|
musicbrainz_id: api_response["mbid"],
|
||||||
name: api_response["name"],
|
name: api_response["name"],
|
||||||
bio: api_response["bio"]["content"],
|
bio: api_response["bio"]["content"] || "",
|
||||||
image: get_image(api_response),
|
image: get_image(api_response),
|
||||||
play_count: get_play_count(api_response)
|
play_count: get_play_count(api_response)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,14 @@ defmodule MusicLibraryWeb.ArtistLive.Show do
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
defp render_bio(nil), do: gettext("Biography not available")
|
defp bio_available?(artist_info_result) do
|
||||||
|
artist_info_result.ok? && artist_info_result.result && artist_info_result.result.bio !== ""
|
||||||
|
end
|
||||||
|
|
||||||
|
defp played?(artist_info_result) do
|
||||||
|
artist_info_result.ok? && artist_info_result.result &&
|
||||||
|
artist_info_result.result.play_count > 0
|
||||||
|
end
|
||||||
|
|
||||||
# Bios start with text, then a link to read more on Last.fm, followed by a license text.
|
# Bios start with text, then a link to read more on Last.fm, followed by a license text.
|
||||||
# We split the bio at the read more link in order to render the license separately.
|
# We split the bio at the read more link in order to render the license separately.
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<div class="mt-4 px-4 sm:px-6 lg:px-8">
|
<div class="mt-4 px-4 sm:px-6 lg:px-8">
|
||||||
<h1 class="flex items-end mt-1 font-semibold text-2xl leading-5 text-zinc-700 dark:text-zinc-300 text-wrap">
|
<h1 class="flex items-end mt-1 font-semibold text-2xl leading-5 text-zinc-700 dark:text-zinc-300 text-wrap">
|
||||||
{@artist.name}
|
{@artist.name}
|
||||||
<span :if={@artist_info.ok? && @artist_info.result && @artist_info.result.play_count > 0}>
|
<span :if={played?(@artist_info)}>
|
||||||
<span class="sr-only">
|
<span class="sr-only">
|
||||||
{gettext("Number of scrobbles")}
|
{gettext("Number of scrobbles")}
|
||||||
</span>
|
</span>
|
||||||
@@ -18,13 +18,16 @@
|
|||||||
</span>
|
</span>
|
||||||
</h1>
|
</h1>
|
||||||
<details
|
<details
|
||||||
:if={artist_info = @artist_info.ok? && @artist_info.result}
|
:if={bio_available?(@artist_info)}
|
||||||
class="mt-4 text-sm leading-5 text-zinc-500 dark:text-zinc-400"
|
class="mt-4 text-sm leading-5 text-zinc-500 dark:text-zinc-400"
|
||||||
>
|
>
|
||||||
<summary class="text-sm mb-4">{gettext("Biography")}</summary>
|
<summary class="text-sm mb-4">{gettext("Biography")}</summary>
|
||||||
{render_bio(artist_info.bio)}
|
{render_bio(@artist_info.result.bio)}
|
||||||
</details>
|
</details>
|
||||||
<div :if={!@artist_info.ok?} class="mt-4 text-sm leading-5 text-zinc-500 dark:text-zinc-400">
|
<div
|
||||||
|
:if={!bio_available?(@artist_info)}
|
||||||
|
class="mt-4 text-sm leading-5 text-zinc-500 dark:text-zinc-400"
|
||||||
|
>
|
||||||
{gettext("Biography not available")}
|
{gettext("Biography not available")}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ msgid "Choose a value"
|
|||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: lib/music_library_web/components/layouts/app.html.heex:13
|
#: lib/music_library_web/components/layouts/app.html.heex:13
|
||||||
#: lib/music_library_web/live/artist_live/show.html.heex:33
|
#: lib/music_library_web/live/artist_live/show.html.heex:36
|
||||||
#: lib/music_library_web/live/collection_live/index.ex:77
|
#: lib/music_library_web/live/collection_live/index.ex:77
|
||||||
#: lib/music_library_web/live/collection_live/show.ex:102
|
#: lib/music_library_web/live/collection_live/show.ex:102
|
||||||
#: lib/music_library_web/live/collection_live/show.ex:119
|
#: lib/music_library_web/live/collection_live/show.ex:119
|
||||||
@@ -328,7 +328,7 @@ msgid "Welcome to your Music Library"
|
|||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: lib/music_library_web/components/layouts/app.html.heex:19
|
#: lib/music_library_web/components/layouts/app.html.heex:19
|
||||||
#: lib/music_library_web/live/artist_live/show.html.heex:71
|
#: lib/music_library_web/live/artist_live/show.html.heex:74
|
||||||
#: lib/music_library_web/live/wishlist_live/index.ex:75
|
#: lib/music_library_web/live/wishlist_live/index.ex:75
|
||||||
#: lib/music_library_web/live/wishlist_live/show.ex:102
|
#: lib/music_library_web/live/wishlist_live/show.ex:102
|
||||||
#, elixir-autogen, elixir-format
|
#, elixir-autogen, elixir-format
|
||||||
@@ -477,14 +477,13 @@ msgstr ""
|
|||||||
msgid "Dev dashboard"
|
msgid "Dev dashboard"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: lib/music_library_web/live/artist_live/show.ex:53
|
#: lib/music_library_web/live/artist_live/show.html.heex:31
|
||||||
#: lib/music_library_web/live/artist_live/show.html.heex:28
|
|
||||||
#, elixir-autogen, elixir-format
|
#, elixir-autogen, elixir-format
|
||||||
msgid "Biography not available"
|
msgid "Biography not available"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#: lib/music_library_web/live/artist_live/show.html.heex:51
|
#: lib/music_library_web/live/artist_live/show.html.heex:54
|
||||||
#: lib/music_library_web/live/artist_live/show.html.heex:89
|
#: lib/music_library_web/live/artist_live/show.html.heex:92
|
||||||
#, elixir-autogen, elixir-format
|
#, elixir-autogen, elixir-format
|
||||||
msgid "View details"
|
msgid "View details"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|||||||
Reference in New Issue
Block a user