From df46759a8d06c5bdc67d66d83c0d00fd4cece98b Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Sun, 17 Aug 2025 23:30:21 +0300 Subject: [PATCH] Extract top artists component and lazy load each tab --- lib/music_library/scrobble_activity.ex | 22 +-- .../components/stats_components.ex | 45 ----- .../live/stats_live/index.ex | 20 +-- .../live/stats_live/index.html.heex | 33 +--- .../live/stats_live/top_artists.ex | 158 ++++++++++++++++++ priv/gettext/default.pot | 10 +- priv/gettext/en/LC_MESSAGES/default.po | 10 +- 7 files changed, 179 insertions(+), 119 deletions(-) create mode 100644 lib/music_library_web/live/stats_live/top_artists.ex diff --git a/lib/music_library/scrobble_activity.ex b/lib/music_library/scrobble_activity.ex index ebc58005..54eb478e 100644 --- a/lib/music_library/scrobble_activity.ex +++ b/lib/music_library/scrobble_activity.ex @@ -360,21 +360,17 @@ defmodule MusicLibrary.ScrobbleActivity do end @doc """ - Gets top artists for multiple time periods (30, 90, 365 days) and all time. - Returns a map with the results for each period. + Gets top artists for a time period (30, 90, 365 days) and all time. """ - def get_top_artists_by_periods(opts) do - last_30_days = get_top_artists_by_days(30, opts) - last_90_days = get_top_artists_by_days(90, opts) - last_365_days = get_top_artists_by_days(365, opts) - all_time = get_top_artists(opts) + def get_top_artists_by_period(opts) do + period = Keyword.get(opts, :period, :last_30_days) - %{ - last_30_days: last_30_days, - last_90_days: last_90_days, - last_365_days: last_365_days, - all_time: all_time - } + case period do + :all_time -> get_top_artists(opts) + :last_30_days -> get_top_artists_by_days(30, opts) + :last_90_days -> get_top_artists_by_days(90, opts) + :last_365_days -> get_top_artists_by_days(365, opts) + end end defp resolve_timezone! do diff --git a/lib/music_library_web/components/stats_components.ex b/lib/music_library_web/components/stats_components.ex index ab9fb13c..972125c9 100644 --- a/lib/music_library_web/components/stats_components.ex +++ b/lib/music_library_web/components/stats_components.ex @@ -66,51 +66,6 @@ defmodule MusicLibraryWeb.StatsComponents do """ end - attr :artists, :list, required: true - - def top_artists_by_period(assigns) do - ~H""" -
-
-
- {artist.artist_name} ~p"/images/cover-not-found.png" <> "';"} - /> -
- <.icon name="hero-user" class="w-6 h-6 text-zinc-400" /> -
-
-

- {artist.artist_name} -

-
- <.badge> - {artist.play_count} - -
-
-
- """ - end - def refresh_lastfm_feed_button(assigns) do ~H"""