Add status for each track in the scrobble activity

This commit is contained in:
Claudio Ortolina
2024-11-13 11:53:45 +00:00
parent a0947b07f3
commit 80f945555c
5 changed files with 79 additions and 6 deletions
+10
View File
@@ -46,6 +46,16 @@ defmodule MusicLibrary.Collection do
Repo.one!(q)
end
def collected_release_ids(release_ids) do
q =
from r in fragment("records, json_each(records.release_ids)"),
where: r.value in ^release_ids,
where: fragment("records.purchased_at IS NOT NULL"),
select: r.value
Repo.all(q)
end
defp base_search do
from r in Record,
where: not is_nil(r.purchased_at)
+10
View File
@@ -20,6 +20,16 @@ defmodule MusicLibrary.Wishlist do
Repo.aggregate(base_search(), :count)
end
def wishlisted_release_ids(release_ids) do
q =
from r in fragment("records, json_each(records.release_ids)"),
where: r.value in ^release_ids,
where: fragment("records.purchased_at IS NULL"),
select: r.value
Repo.all(q)
end
defp base_search do
from r in Record,
where: is_nil(r.purchased_at)
@@ -20,6 +20,14 @@ defmodule MusicLibraryWeb.StatsLive.Index do
recent_tracks = LastFm.Feed.all()
release_ids =
recent_tracks
|> Enum.map(fn t -> t.album.musicbrainz_id end)
|> Enum.uniq()
collected_release_ids = Collection.collected_release_ids(release_ids)
wishlisted_release_ids = Wishlist.wishlisted_release_ids(release_ids)
if connected?(socket) do
LastFm.Feed.subscribe()
end
@@ -37,6 +45,8 @@ defmodule MusicLibraryWeb.StatsLive.Index do
collection_count: collection_count,
wishlist_count: wishlist_count,
latest_record: latest_record,
collected_release_ids: collected_release_ids,
wishlisted_release_ids: wishlisted_release_ids,
nav_section: :stats
)}
end
@@ -100,7 +100,40 @@
</div>
</div>
<div class="relative flex-none">
<span
:if={track.album.musicbrainz_id in @collected_release_ids}
class={[
"inline-flex items-center rounded-md",
"px-2 py-1 text-xs font-medium",
"ring-1 ring-inset",
"bg-green-50 dark:bg-green-500/10",
"text-green-700 dark:text-green-400",
"ring-green-600/20 dark:ring-green-500/20"
]}
>
<%= gettext("Collected") %>
</span>
<span
:if={track.album.musicbrainz_id in @wishlisted_release_ids}
class={[
"inline-flex items-center rounded-md",
"px-2 py-1 text-xs font-medium",
"ring-1 ring-inset",
"bg-yellow-50 dark:bg-yellow-400/10",
"text-yellow-800 dark:text-yellow-500",
"ring-yellow-600/20 dark:ring-yellow-400/20"
]}
>
<%= gettext("Wishlisted") %>
</span>
<div
:if={
track.album.musicbrainz_id not in @collected_release_ids and
track.album.musicbrainz_id not in @wishlisted_release_ids
}
class="relative flex-none"
>
<button
type="button"
class="text-zinc-500 hover:text-zinc-900 dark:text-zinc-400 dark:hover:text-zinc-300"