Add badge for tracks whose albums cannot be imported
Includes a small optimization that removes "" release IDs from the list of IDs checked against releases in the database.
This commit is contained in:
@@ -20,10 +20,7 @@ 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()
|
||||
release_ids = release_ids(recent_tracks)
|
||||
|
||||
collected_release_ids = Collection.collected_release_ids(release_ids)
|
||||
wishlisted_release_ids = Wishlist.wishlisted_release_ids(release_ids)
|
||||
@@ -83,10 +80,7 @@ defmodule MusicLibraryWeb.StatsLive.Index do
|
||||
end
|
||||
|
||||
def handle_info(%{tracks: recent_tracks}, socket) do
|
||||
release_ids =
|
||||
recent_tracks
|
||||
|> Enum.map(fn t -> t.album.musicbrainz_id end)
|
||||
|> Enum.uniq()
|
||||
release_ids = release_ids(recent_tracks)
|
||||
|
||||
collected_release_ids = Collection.collected_release_ids(release_ids)
|
||||
wishlisted_release_ids = Wishlist.wishlisted_release_ids(release_ids)
|
||||
@@ -100,6 +94,13 @@ defmodule MusicLibraryWeb.StatsLive.Index do
|
||||
|> stream(:recent_tracks, recent_tracks, reset: true)}
|
||||
end
|
||||
|
||||
defp release_ids(recent_tracks) do
|
||||
recent_tracks
|
||||
|> Enum.map(fn t -> t.album.musicbrainz_id end)
|
||||
|> Enum.uniq()
|
||||
|> Enum.reject(fn musicbrainz_id -> musicbrainz_id == "" end)
|
||||
end
|
||||
|
||||
# The Tailwind build step requires all needed classes to be explicitly referenced
|
||||
# in the source code, and not dynamically generated. This implies that one cannot
|
||||
# (for example) interpolate a number in a class name.
|
||||
|
||||
@@ -114,6 +114,19 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<span
|
||||
:if={track.album.musicbrainz_id == ""}
|
||||
class={[
|
||||
"inline-flex items-center rounded-md",
|
||||
"px-2 py-1 text-xs font-medium",
|
||||
"ring-1 ring-inset",
|
||||
"bg-zinc-50 dark:bg-zinc-500/10",
|
||||
"text-zinc-700 dark:text-zinc-400",
|
||||
"ring-zinc-600/20 dark:ring-zinc-500/20"
|
||||
]}
|
||||
>
|
||||
<%= gettext("No MusicBrainz ID") %>
|
||||
</span>
|
||||
<span
|
||||
:if={track.album.musicbrainz_id in @collected_release_ids}
|
||||
class={[
|
||||
@@ -143,7 +156,8 @@
|
||||
|
||||
<div
|
||||
:if={
|
||||
track.album.musicbrainz_id not in @collected_release_ids and
|
||||
track.album.musicbrainz_id !== "" and
|
||||
track.album.musicbrainz_id not in @collected_release_ids and
|
||||
track.album.musicbrainz_id not in @wishlisted_release_ids
|
||||
}
|
||||
class="relative flex-none"
|
||||
|
||||
@@ -82,8 +82,8 @@ msgid "Edit"
|
||||
msgstr ""
|
||||
|
||||
#: lib/music_library_web/live/collection_live/index.ex:121
|
||||
#: lib/music_library_web/live/stats_live/index.ex:70
|
||||
#: lib/music_library_web/live/stats_live/index.ex:76
|
||||
#: lib/music_library_web/live/stats_live/index.ex:67
|
||||
#: lib/music_library_web/live/stats_live/index.ex:73
|
||||
#: lib/music_library_web/live/wishlist_live/index.ex:117
|
||||
#: lib/music_library_web/live/wishlist_live/index.ex:124
|
||||
#, elixir-autogen, elixir-format
|
||||
@@ -210,7 +210,7 @@ msgid "Purchased on"
|
||||
msgstr ""
|
||||
|
||||
#: lib/music_library_web/live/collection_live/index.ex:112
|
||||
#: lib/music_library_web/live/stats_live/index.ex:62
|
||||
#: lib/music_library_web/live/stats_live/index.ex:59
|
||||
#: lib/music_library_web/live/wishlist_live/index.ex:109
|
||||
#, elixir-autogen, elixir-format
|
||||
msgid "Record imported successfully"
|
||||
@@ -273,7 +273,7 @@ msgid "Something went wrong!"
|
||||
msgstr ""
|
||||
|
||||
#: lib/music_library_web/components/layouts/app.html.heex:7
|
||||
#: lib/music_library_web/live/stats_live/index.ex:42
|
||||
#: lib/music_library_web/live/stats_live/index.ex:39
|
||||
#, elixir-autogen, elixir-format
|
||||
msgid "Stats"
|
||||
msgstr ""
|
||||
@@ -368,17 +368,17 @@ msgid "Scrobble activity"
|
||||
msgstr ""
|
||||
|
||||
#: lib/music_library_web/live/record_live/import_component.ex:80
|
||||
#: lib/music_library_web/live/stats_live/index.html.heex:159
|
||||
#: lib/music_library_web/live/stats_live/index.html.heex:173
|
||||
#, elixir-autogen, elixir-format
|
||||
msgid "Choose which format to import"
|
||||
msgstr ""
|
||||
|
||||
#: lib/music_library_web/live/stats_live/index.html.heex:128
|
||||
#: lib/music_library_web/live/stats_live/index.html.heex:141
|
||||
#, elixir-autogen, elixir-format
|
||||
msgid "Collected"
|
||||
msgstr ""
|
||||
|
||||
#: lib/music_library_web/live/stats_live/index.html.heex:141
|
||||
#: lib/music_library_web/live/stats_live/index.html.heex:154
|
||||
#, elixir-autogen, elixir-format
|
||||
msgid "Wishlisted"
|
||||
msgstr ""
|
||||
@@ -449,3 +449,8 @@ msgstr ""
|
||||
#, elixir-autogen, elixir-format
|
||||
msgid "Error refreshing cover"
|
||||
msgstr ""
|
||||
|
||||
#: lib/music_library_web/live/stats_live/index.html.heex:128
|
||||
#, elixir-autogen, elixir-format
|
||||
msgid "No MusicBrainz ID"
|
||||
msgstr ""
|
||||
|
||||
@@ -127,10 +127,28 @@ defmodule MusicLibraryWeb.StatsLive.IndexTest do
|
||||
scrobbled_at_label: "20 Nov 2024, 11:54"
|
||||
}
|
||||
|
||||
in_murmuration_track = %LastFm.Track{
|
||||
musicbrainz_id: "",
|
||||
title: "Wait For Me",
|
||||
artist: %LastFm.Artist{
|
||||
musicbrainz_id: "298c6d13-4757-437d-a3a6-07d0b3255e5b",
|
||||
name: "Von Hertzen Brothers"
|
||||
},
|
||||
album: %LastFm.Album{
|
||||
musicbrainz_id: "",
|
||||
title: "In Murmuration"
|
||||
},
|
||||
cover_url:
|
||||
"https://lastfm.freetls.fastly.net/i/u/64s/f4923850113a5d365b1fd2d04cb4c1c3.jpg",
|
||||
scrobbled_at_uts: 1_732_399_832,
|
||||
scrobbled_at_label: "23 Nov 2024, 22:10"
|
||||
}
|
||||
|
||||
LastFm.Feed.update([
|
||||
machinarium_soundtrack_track,
|
||||
the_last_flight_track,
|
||||
the_mystery_of_time_track
|
||||
the_mystery_of_time_track,
|
||||
in_murmuration_track
|
||||
])
|
||||
|
||||
# We add one album to the wishlist, and one to the collection.
|
||||
@@ -164,6 +182,12 @@ defmodule MusicLibraryWeb.StatsLive.IndexTest do
|
||||
"#track-#{the_mystery_of_time_track.scrobbled_at_uts}",
|
||||
"Choose which format to import"
|
||||
)
|
||||
|
||||
assert has_element?(
|
||||
stats_live,
|
||||
"#track-#{in_murmuration_track.scrobbled_at_uts}",
|
||||
"No MusicBrainz ID"
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user