From 7139e0ad8f32e05bbd58d8cc077cfef8e8317878 Mon Sep 17 00:00:00 2001 From: Claudio Ortolina Date: Mon, 4 Nov 2024 12:04:13 +0000 Subject: [PATCH] Render recently scrobbled tracks in stats --- lib/last_fm/supervisor.ex | 12 +++---- lib/music_library/application.ex | 6 +--- .../live/stats_live/index.ex | 3 ++ .../live/stats_live/index.html.heex | 33 +++++++++++++++++++ priv/gettext/default.pot | 7 +++- 5 files changed, 49 insertions(+), 12 deletions(-) diff --git a/lib/last_fm/supervisor.ex b/lib/last_fm/supervisor.ex index c931def5..2e155746 100644 --- a/lib/last_fm/supervisor.ex +++ b/lib/last_fm/supervisor.ex @@ -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 diff --git a/lib/music_library/application.ex b/lib/music_library/application.ex index 7d0a9234..5cf2a0c6 100644 --- a/lib/music_library/application.ex +++ b/lib/music_library/application.ex @@ -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 diff --git a/lib/music_library_web/live/stats_live/index.ex b/lib/music_library_web/live/stats_live/index.ex index 2ab98ece..16e11002 100644 --- a/lib/music_library_web/live/stats_live/index.ex +++ b/lib/music_library_web/live/stats_live/index.ex @@ -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 diff --git a/lib/music_library_web/live/stats_live/index.html.heex b/lib/music_library_web/live/stats_live/index.html.heex index 57743413..8266ec64 100644 --- a/lib/music_library_web/live/stats_live/index.html.heex +++ b/lib/music_library_web/live/stats_live/index.html.heex @@ -60,3 +60,36 @@ + +
+

+ <%= gettext("Scrobble activity") %> +

+ +
diff --git a/priv/gettext/default.pot b/priv/gettext/default.pot index bfff45d8..a49769ef 100644 --- a/priv/gettext/default.pot +++ b/priv/gettext/default.pot @@ -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 ""