Make stats feed update automatically
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user