Can refresh feed from scrobbled tracks view
This commit is contained in:
@@ -2,6 +2,7 @@ defmodule MusicLibraryWeb.ScrobbledTracksLive.Index do
|
||||
use MusicLibraryWeb, :live_view
|
||||
|
||||
import MusicLibraryWeb.Components.Pagination
|
||||
import MusicLibraryWeb.ScrobbleComponents, only: [refresh_lastfm_feed_button: 1]
|
||||
|
||||
alias LastFm.Track
|
||||
alias MusicLibrary.ScrobbleActivity
|
||||
@@ -20,6 +21,10 @@ defmodule MusicLibraryWeb.ScrobbledTracksLive.Index do
|
||||
|> assign(:current_section, :scrobble_activity)
|
||||
|> stream_configure(:tracks, dom_id: fn %Track{scrobbled_at_uts: id} -> "tracks-#{id}" end)
|
||||
|
||||
if connected?(socket) do
|
||||
LastFm.subscribe_to_feed()
|
||||
end
|
||||
|
||||
{:ok, socket}
|
||||
end
|
||||
|
||||
@@ -66,6 +71,14 @@ defmodule MusicLibraryWeb.ScrobbledTracksLive.Index do
|
||||
{:noreply, load_and_assign_tracks(socket, socket.assigns.track_list_params)}
|
||||
end
|
||||
|
||||
def handle_info(%{track_count: 0}, socket) do
|
||||
{:noreply, socket}
|
||||
end
|
||||
|
||||
def handle_info(%{track_count: _count}, socket) do
|
||||
{:noreply, load_and_assign_tracks(socket, socket.assigns.track_list_params)}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_event("delete", %{"scrobbled-at-uts" => scrobbled_at_uts}, socket) do
|
||||
track = ScrobbleActivity.get_track!(scrobbled_at_uts)
|
||||
@@ -83,6 +96,11 @@ defmodule MusicLibraryWeb.ScrobbledTracksLive.Index do
|
||||
{:noreply, push_patch(socket, to: ~p"/scrobbled-tracks?#{qs}")}
|
||||
end
|
||||
|
||||
def handle_event("refresh_lastfm_feed", _, socket) do
|
||||
LastFm.refresh_scrobbled_tracks()
|
||||
{:noreply, socket}
|
||||
end
|
||||
|
||||
defp parse_order("scrobbled_at"), do: :scrobbled_at
|
||||
defp parse_order("title"), do: :title
|
||||
defp parse_order("artist"), do: :artist
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="flex items-end gap-6 mt-8 justify-center sm:justify-start">
|
||||
<div class="flex items-end gap-6 mt-8 justify-between">
|
||||
<.button_group>
|
||||
<.button
|
||||
patch={order_path(@track_list_params, :scrobbled_at)}
|
||||
@@ -54,6 +54,7 @@
|
||||
{gettext("Album")}
|
||||
</.button>
|
||||
</.button_group>
|
||||
<.refresh_lastfm_feed_button />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ defmodule MusicLibraryWeb.StatsLive.Index do
|
||||
import MusicLibraryWeb.ChartComponents
|
||||
import MusicLibraryWeb.RecordComponents, only: [format_label: 1, type_label: 1]
|
||||
import MusicLibraryWeb.StatsComponents
|
||||
import MusicLibraryWeb.ScrobbleComponents, only: [refresh_lastfm_feed_button: 1]
|
||||
|
||||
alias MusicLibrary.Assets.Transform
|
||||
alias MusicLibrary.{Collection, Records, ScrobbleActivity, Wishlist}
|
||||
|
||||
Reference in New Issue
Block a user