Make top albums clickable
This commit is contained in:
@@ -223,9 +223,10 @@ defmodule MusicLibrary.ScrobbleActivity do
|
|||||||
select: %{
|
select: %{
|
||||||
album_title: fragment("json_extract(album, '$.title')"),
|
album_title: fragment("json_extract(album, '$.title')"),
|
||||||
artist_name: fragment("json_extract(artist, '$.name')"),
|
artist_name: fragment("json_extract(artist, '$.name')"),
|
||||||
|
artist_musicbrainz_id: fragment("json_extract(artist, '$.musicbrainz_id')"),
|
||||||
play_count: count(t.scrobbled_at_uts),
|
play_count: count(t.scrobbled_at_uts),
|
||||||
cover_url: fragment("max(?)", t.cover_url),
|
cover_url: fragment("max(?)", t.cover_url),
|
||||||
album_mbid: fragment("json_extract(album, '$.musicbrainz_id')")
|
album_musicbrainz_id: fragment("json_extract(album, '$.musicbrainz_id')")
|
||||||
},
|
},
|
||||||
order_by: [desc: count(t.scrobbled_at_uts)],
|
order_by: [desc: count(t.scrobbled_at_uts)],
|
||||||
limit: ^limit
|
limit: ^limit
|
||||||
@@ -235,10 +236,26 @@ defmodule MusicLibrary.ScrobbleActivity do
|
|||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Gets top albums for multiple time periods (30, 90, 365 days).
|
Gets top albums for multiple time periods (30, 90, 365 days).
|
||||||
Returns a map with the results for each period.
|
Returns a map with the results for each period, along with collected and
|
||||||
|
wishlisted releases.
|
||||||
"""
|
"""
|
||||||
def get_top_albums_by_periods(limit \\ 10) do
|
def get_top_albums_by_periods(limit \\ 10) do
|
||||||
|
last_30_days = get_top_albums_by_days(30, limit)
|
||||||
|
last_90_days = get_top_albums_by_days(90, limit)
|
||||||
|
last_365_days = get_top_albums_by_days(365, limit)
|
||||||
|
|
||||||
|
all_album_ids =
|
||||||
|
(last_30_days ++ last_90_days ++ last_365_days)
|
||||||
|
|> Enum.map(fn t -> t.album_musicbrainz_id end)
|
||||||
|
|> Enum.uniq()
|
||||||
|
|> Enum.reject(fn musicbrainz_id -> musicbrainz_id == "" end)
|
||||||
|
|
||||||
|
collected_releases = Collection.collected_releases(all_album_ids)
|
||||||
|
wishlisted_releases = Wishlist.wishlisted_releases(all_album_ids)
|
||||||
|
|
||||||
%{
|
%{
|
||||||
|
collected_releases: collected_releases,
|
||||||
|
wishlisted_releases: wishlisted_releases,
|
||||||
last_30_days: get_top_albums_by_days(30, limit),
|
last_30_days: get_top_albums_by_days(30, limit),
|
||||||
last_90_days: get_top_albums_by_days(90, limit),
|
last_90_days: get_top_albums_by_days(90, limit),
|
||||||
last_365_days: get_top_albums_by_days(365, limit)
|
last_365_days: get_top_albums_by_days(365, limit)
|
||||||
|
|||||||
@@ -71,8 +71,23 @@ defmodule MusicLibraryWeb.StatsLive.Index do
|
|||||||
"""
|
"""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp navigate_to_record(collected_releases, wishlisted_releases, musicbrainz_id) do
|
||||||
|
cond do
|
||||||
|
record_id = tracked_record?(collected_releases, musicbrainz_id) ->
|
||||||
|
JS.navigate(~p"/collection/#{record_id}")
|
||||||
|
|
||||||
|
record_id = tracked_record?(wishlisted_releases, musicbrainz_id) ->
|
||||||
|
JS.navigate(~p"/wishlist/#{record_id}")
|
||||||
|
|
||||||
|
true ->
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
attr :albums, :list, required: true
|
attr :albums, :list, required: true
|
||||||
attr :title, :string, required: true
|
attr :title, :string, required: true
|
||||||
|
attr :collected_releases, :list, required: true
|
||||||
|
attr :wishlisted_releases, :list, required: true
|
||||||
|
|
||||||
def top_albums_by_period(assigns) do
|
def top_albums_by_period(assigns) do
|
||||||
~H"""
|
~H"""
|
||||||
@@ -81,7 +96,17 @@ defmodule MusicLibraryWeb.StatsLive.Index do
|
|||||||
{@title}
|
{@title}
|
||||||
</h2>
|
</h2>
|
||||||
<div class="space-y-2">
|
<div class="space-y-2">
|
||||||
<div :for={album <- @albums} class="flex items-center space-x-3 p-2">
|
<div
|
||||||
|
:for={album <- @albums}
|
||||||
|
phx-click={
|
||||||
|
navigate_to_record(@collected_releases, @wishlisted_releases, album.album_musicbrainz_id)
|
||||||
|
}
|
||||||
|
class={[
|
||||||
|
"flex items-center space-x-3 p-2",
|
||||||
|
tracked_record?(@collected_releases ++ @wishlisted_releases, album.album_musicbrainz_id) &&
|
||||||
|
"cursor-pointer"
|
||||||
|
]}
|
||||||
|
>
|
||||||
<img
|
<img
|
||||||
class="w-12 h-12 rounded-md object-cover"
|
class="w-12 h-12 rounded-md object-cover"
|
||||||
src={album.cover_url}
|
src={album.cover_url}
|
||||||
|
|||||||
@@ -74,9 +74,24 @@
|
|||||||
</h1>
|
</h1>
|
||||||
|
|
||||||
<div class="mt-5 grid grid-cols-1 lg:grid-cols-3 gap-5">
|
<div class="mt-5 grid grid-cols-1 lg:grid-cols-3 gap-5">
|
||||||
<.top_albums_by_period albums={@top_albums.last_30_days} title={gettext("Last 30 days")} />
|
<.top_albums_by_period
|
||||||
<.top_albums_by_period albums={@top_albums.last_90_days} title={gettext("Last 90 days")} />
|
albums={@top_albums.last_30_days}
|
||||||
<.top_albums_by_period albums={@top_albums.last_365_days} title={gettext("Last year")} />
|
title={gettext("Last 30 days")}
|
||||||
|
collected_releases={@top_albums.collected_releases}
|
||||||
|
wishlisted_releases={@top_albums.wishlisted_releases}
|
||||||
|
/>
|
||||||
|
<.top_albums_by_period
|
||||||
|
albums={@top_albums.last_90_days}
|
||||||
|
title={gettext("Last 90 days")}
|
||||||
|
collected_releases={@top_albums.collected_releases}
|
||||||
|
wishlisted_releases={@top_albums.wishlisted_releases}
|
||||||
|
/>
|
||||||
|
<.top_albums_by_period
|
||||||
|
albums={@top_albums.last_365_days}
|
||||||
|
title={gettext("Last year")}
|
||||||
|
collected_releases={@top_albums.collected_releases}
|
||||||
|
wishlisted_releases={@top_albums.wishlisted_releases}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user