Render recently scrobbled tracks in stats

This commit is contained in:
Claudio Ortolina
2024-11-04 12:04:13 +00:00
parent d818cdbae5
commit 7139e0ad8f
5 changed files with 49 additions and 12 deletions
+6 -6
View File
@@ -6,15 +6,11 @@ defmodule LastFm.Supervisor do
end
@impl true
def init(opts) do
def init(_opts) do
:ok = LastFm.Feed.create_table!()
api =
Keyword.fetch!(opts, :api)
|> IO.inspect()
children = [
{LastFm.Refresh, %{api: api, user: "cloud8421", api_key: api_key()}}
{LastFm.Refresh, %{api: api(), user: "cloud8421", api_key: api_key()}}
]
Supervisor.init(children, strategy: :one_for_one)
@@ -24,4 +20,8 @@ defmodule LastFm.Supervisor do
Application.get_env(:music_library, LastFm, [])
|> Keyword.get(:api_key)
end
defp api do
Application.get_env(:music_library, :last_fm, LastFm.APIImpl)
end
end
+1 -5
View File
@@ -15,7 +15,7 @@ defmodule MusicLibrary.Application do
repos: Application.fetch_env!(:music_library, :ecto_repos), skip: skip_migrations?()},
{DNSCluster, query: Application.get_env(:music_library, :dns_cluster_query) || :ignore},
{Phoenix.PubSub, name: MusicLibrary.PubSub},
{LastFm.Supervisor, api: last_fm()},
LastFm.Supervisor,
# Start a worker by calling: MusicLibrary.Worker.start_link(arg)
# {MusicLibrary.Worker, arg},
# Start to serve requests, typically the last entry
@@ -40,8 +40,4 @@ defmodule MusicLibrary.Application do
# By default, sqlite migrations are run when using a release
System.get_env("RELEASE_NAME") != nil
end
defp last_fm do
Application.get_env(:music_library, :last_fm, LastFm.APIImpl)
end
end
@@ -18,6 +18,8 @@ defmodule MusicLibraryWeb.StatsLive.Index do
latest_record = Records.get_latest_record!()
recent_tracks = LastFm.Feed.all()
{:ok,
socket
|> assign(
@@ -27,6 +29,7 @@ defmodule MusicLibraryWeb.StatsLive.Index do
collection_count: collection_count,
wishlist_count: wishlist_count,
latest_record: latest_record,
recent_tracks: recent_tracks,
nav_section: :stats
)}
end
@@ -60,3 +60,36 @@
</div>
</dl>
</div>
<div class="flow-root">
<h1 class="mt-5 text-base lg:text-2xl text-gray-900 dark:text-gray-200 font-semibold">
<%= gettext("Scrobble activity") %>
</h1>
<ul role="list" class="-mb-8 mt-5">
<li :for={{id, track} <- @recent_tracks} id={"track-#{id}"} class="group">
<div class="relative pb-8">
<span
class="group-last:hidden absolute left-6 top-6 -ml-px h-full w-0.5 bg-gray-200"
aria-hidden="true"
>
</span>
<div class="relative flex space-x-3 items-center">
<img class="h-12 w-12 rounded-md" src={track.cover_url} alt={track.title} />
<div class="flex min-w-0 flex-1 justify-between space-x-4">
<div class="font-semibold">
<p class="text-sm md:text-base block text-zinc-700 hover:text-zinc-500 dark:text-zinc-400 dark:hover:text-zinc-300">
<%= track.artist.name %>
</p>
<p class="text-sm md:text-base text-zinc-700 dark:text-zinc-300">
<%= track.title %>
</p>
</div>
<div class="whitespace-nowrap text-right text-xs sm:text-sm text-zinc-500 dark:text-zinc-400">
<%= track.scrobbled_at_label %>
</div>
</div>
</div>
</div>
</li>
</ul>
</div>
+6 -1
View File
@@ -269,7 +269,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:24
#: lib/music_library_web/live/stats_live/index.ex:26
#, elixir-autogen, elixir-format
msgid "Stats"
msgstr ""
@@ -357,3 +357,8 @@ msgstr ""
#, elixir-autogen, elixir-format
msgid "MusicBrainz data"
msgstr ""
#: lib/music_library_web/live/stats_live/index.html.heex:66
#, elixir-autogen, elixir-format
msgid "Scrobble activity"
msgstr ""