From 109913cbfd0fda1a295cc0d2143215c943516f8a Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Sat, 14 Jun 2025 09:44:47 +0300 Subject: [PATCH] Extract top albums to components --- .../live/stats_live/index.ex | 33 ++++++++ .../live/stats_live/index.html.heex | 80 +------------------ priv/gettext/default.pot | 4 +- priv/gettext/en/LC_MESSAGES/default.po | 6 +- 4 files changed, 41 insertions(+), 82 deletions(-) diff --git a/lib/music_library_web/live/stats_live/index.ex b/lib/music_library_web/live/stats_live/index.ex index 605cbc8f..37fbc0a4 100644 --- a/lib/music_library_web/live/stats_live/index.ex +++ b/lib/music_library_web/live/stats_live/index.ex @@ -71,6 +71,39 @@ defmodule MusicLibraryWeb.StatsLive.Index do """ end + attr :albums, :list, required: true + attr :title, :string, required: true + + def top_albums_by_period(assigns) do + ~H""" +
+

+ {@title} +

+
+
+ {album.album_title} +
+

+ {album.artist_name} +

+

+ {album.album_title} +

+
+
+ {album.play_count} +
+
+
+
+ """ + end + def mount(_params, _session, socket) do latest_record = Collection.get_latest_record!() recent_tracks = LastFm.get_scrobbled_tracks() diff --git a/lib/music_library_web/live/stats_live/index.html.heex b/lib/music_library_web/live/stats_live/index.html.heex index 9f92196d..fbe063d4 100644 --- a/lib/music_library_web/live/stats_live/index.html.heex +++ b/lib/music_library_web/live/stats_live/index.html.heex @@ -118,83 +118,9 @@
-
-

- {gettext("Last 30 days")} -

-
-
- {album.album_title} -
-

- {album.artist_name} -

-

- {album.album_title} -

-
-
- {album.play_count} -
-
-
-
- -
-

- {gettext("Last 90 days")} -

-
-
- {album.album_title} -
-

- {album.artist_name} -

-

- {album.album_title} -

-
-
- {album.play_count} -
-
-
-
- -
-

- {gettext("Last Year")} -

-
-
- {album.album_title} -
-

- {album.artist_name} -

-

- {album.album_title} -

-
-
- {album.play_count} -
-
-
-
+ <.top_albums_by_period albums={@top_albums.last_30_days} title={gettext("Last 30 days")} /> + <.top_albums_by_period albums={@top_albums.last_90_days} title={gettext("Last 90 days")} /> + <.top_albums_by_period albums={@top_albums.last_365_days} title={gettext("Last year")} />
diff --git a/priv/gettext/default.pot b/priv/gettext/default.pot index 5d1df700..0c6776d8 100644 --- a/priv/gettext/default.pot +++ b/priv/gettext/default.pot @@ -898,10 +898,10 @@ msgstr "" #: lib/music_library_web/live/stats_live/index.html.heex #, elixir-autogen, elixir-format -msgid "Last Year" +msgid "Top Albums" msgstr "" #: lib/music_library_web/live/stats_live/index.html.heex #, elixir-autogen, elixir-format -msgid "Top Albums" +msgid "Last year" msgstr "" diff --git a/priv/gettext/en/LC_MESSAGES/default.po b/priv/gettext/en/LC_MESSAGES/default.po index 251c57d6..79de3dbe 100644 --- a/priv/gettext/en/LC_MESSAGES/default.po +++ b/priv/gettext/en/LC_MESSAGES/default.po @@ -897,11 +897,11 @@ msgid "Last 90 days" msgstr "" #: lib/music_library_web/live/stats_live/index.html.heex -#, elixir-autogen, elixir-format -msgid "Last Year" +#, elixir-autogen, elixir-format, fuzzy +msgid "Top Albums" msgstr "" #: lib/music_library_web/live/stats_live/index.html.heex #, elixir-autogen, elixir-format, fuzzy -msgid "Top Albums" +msgid "Last year" msgstr ""