Make stats feed update automatically

This commit is contained in:
Claudio Ortolina
2024-11-04 12:22:23 +00:00
parent 7139e0ad8f
commit 065ca4bf7c
5 changed files with 42 additions and 2 deletions
@@ -20,6 +20,10 @@ defmodule MusicLibraryWeb.StatsLive.Index do
recent_tracks = LastFm.Feed.all()
if connected?(socket) do
LastFm.Feed.subscribe()
end
{:ok,
socket
|> assign(
@@ -34,6 +38,17 @@ defmodule MusicLibraryWeb.StatsLive.Index do
)}
end
def handle_info(%{tracks: tracks}, socket) do
socket =
if socket.assigns.recent_tracks !== tracks do
assign(socket, :recent_tracks, tracks)
else
socket
end
{:noreply, socket}
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.