From 740e94fdf60b42002bed085351f95d3878f903a6 Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Tue, 3 Dec 2024 23:34:25 +0000 Subject: [PATCH] Use <.async_result> component Removes need for custom conditional logic, and covers all needed states. --- .../live/artist_live/show.ex | 9 --- .../live/artist_live/show.html.heex | 79 ++++++++++++------- priv/gettext/default.pot | 37 ++++++--- 3 files changed, 78 insertions(+), 47 deletions(-) diff --git a/lib/music_library_web/live/artist_live/show.ex b/lib/music_library_web/live/artist_live/show.ex index 8977c249..4a8b4e0f 100644 --- a/lib/music_library_web/live/artist_live/show.ex +++ b/lib/music_library_web/live/artist_live/show.ex @@ -50,15 +50,6 @@ defmodule MusicLibraryWeb.ArtistLive.Show do } end - 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. # We split the bio at the read more link in order to render the license separately. @last_fm_link_regex ~r/\.\s*/ diff --git a/lib/music_library_web/live/artist_live/show.html.heex b/lib/music_library_web/live/artist_live/show.html.heex index 1d8d68ed..d7064d81 100644 --- a/lib/music_library_web/live/artist_live/show.html.heex +++ b/lib/music_library_web/live/artist_live/show.html.heex @@ -1,35 +1,60 @@

{@artist.name} - - - {gettext("Number of scrobbles")} + <.async_result :let={artist_info} assign={@artist_info}> + <:loading> +
+ {gettext("Loading play count")} + <.icon + name="hero-arrow-path" + class="-mt-1 h-5 w-5 animate-spin" + aria-hidden="true" + data-slot="icon" + /> +
+ + <:failed :let={_failure}> +
+ {gettext("There was an error loading the play count")} +
+ + 0}> + + {gettext("Number of scrobbles")} + + + {artist_info.play_count} + - - {@artist_info.result.play_count} - -
+

-
- {gettext("Biography")} - {render_bio(@artist_info.result.bio)} -
-
- {gettext("Biography not available")} -
+ + <.async_result :let={artist_info} assign={@artist_info}> + <:loading> +
+ {gettext("Loading biography")} +
+ + <:failed :let={_failure}> +
+ {gettext("There was an error loading the biography")} +
+ +
+ {gettext("Biography")} + {render_bio(@artist_info.result.bio)} +
+

diff --git a/priv/gettext/default.pot b/priv/gettext/default.pot index f7ce2ae4..158875da 100644 --- a/priv/gettext/default.pot +++ b/priv/gettext/default.pot @@ -51,7 +51,7 @@ msgid "Choose a value" msgstr "" #: lib/music_library_web/components/layouts/app.html.heex:13 -#: lib/music_library_web/live/artist_live/show.html.heex:36 +#: lib/music_library_web/live/artist_live/show.html.heex:61 #: 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:119 @@ -328,7 +328,7 @@ msgid "Welcome to your Music Library" msgstr "" #: lib/music_library_web/components/layouts/app.html.heex:19 -#: lib/music_library_web/live/artist_live/show.html.heex:74 +#: lib/music_library_web/live/artist_live/show.html.heex:99 #: lib/music_library_web/live/wishlist_live/index.ex:75 #: lib/music_library_web/live/wishlist_live/show.ex:102 #, elixir-autogen, elixir-format @@ -477,23 +477,38 @@ msgstr "" msgid "Dev dashboard" msgstr "" -#: lib/music_library_web/live/artist_live/show.html.heex:31 -#, elixir-autogen, elixir-format -msgid "Biography not available" -msgstr "" - -#: lib/music_library_web/live/artist_live/show.html.heex:54 -#: lib/music_library_web/live/artist_live/show.html.heex:92 +#: lib/music_library_web/live/artist_live/show.html.heex:79 +#: lib/music_library_web/live/artist_live/show.html.heex:117 #, elixir-autogen, elixir-format msgid "View details" msgstr "" -#: lib/music_library_web/live/artist_live/show.html.heex:6 +#: lib/music_library_web/live/artist_live/show.html.heex:23 #, elixir-autogen, elixir-format msgid "Number of scrobbles" msgstr "" -#: lib/music_library_web/live/artist_live/show.html.heex:24 +#: lib/music_library_web/live/artist_live/show.html.heex:54 #, elixir-autogen, elixir-format msgid "Biography" msgstr "" + +#: lib/music_library_web/live/artist_live/show.html.heex:42 +#, elixir-autogen, elixir-format +msgid "Loading biography" +msgstr "" + +#: lib/music_library_web/live/artist_live/show.html.heex:7 +#, elixir-autogen, elixir-format +msgid "Loading play count" +msgstr "" + +#: lib/music_library_web/live/artist_live/show.html.heex:47 +#, elixir-autogen, elixir-format +msgid "There was an error loading the biography" +msgstr "" + +#: lib/music_library_web/live/artist_live/show.html.heex:18 +#, elixir-autogen, elixir-format +msgid "There was an error loading the play count" +msgstr ""