Extract top albums component

This commit is contained in:
Claudio Ortolina
2025-08-17 14:22:46 +03:00
parent 4637f701c0
commit af7e48507d
6 changed files with 178 additions and 143 deletions
+1 -18
View File
@@ -6,6 +6,7 @@ defmodule MusicLibraryWeb.StatsLive.Index do
import MusicLibraryWeb.StatsComponents
alias MusicLibrary.{Collection, Records, ScrobbleActivity, Wishlist}
alias MusicLibraryWeb.StatsLive.TopAlbums
def mount(_params, _session, socket) do
latest_record = Collection.get_latest_record!()
@@ -28,7 +29,6 @@ defmodule MusicLibraryWeb.StatsLive.Index do
)
|> assign_counts()
|> assign_scrobble_activity(recent_tracks)
|> assign_top_albums()
|> assign_top_artists()
|> assign(
scrobble_activity_mode: "albums",
@@ -87,7 +87,6 @@ defmodule MusicLibraryWeb.StatsLive.Index do
{:noreply,
socket
|> assign_top_albums()
|> assign_top_artists()
|> assign_scrobble_activity(recent_tracks)}
end
@@ -129,22 +128,6 @@ defmodule MusicLibraryWeb.StatsLive.Index do
)
end
defp assign_top_albums(socket) do
timezone = socket.assigns.timezone
current_time = DateTime.utc_now()
assign_async(socket, :top_albums, fn ->
top_albums =
ScrobbleActivity.get_top_albums_by_periods(
limit: 10,
current_time: current_time,
timezone: timezone
)
{:ok, %{top_albums: top_albums}}
end)
end
defp assign_top_artists(socket) do
timezone = socket.assigns.timezone
current_time = DateTime.utc_now()