Can refresh feed from scrobbled tracks view
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
defmodule MusicLibraryWeb.ScrobbleComponents do
|
||||
@moduledoc """
|
||||
Universal search modal and related components.
|
||||
"""
|
||||
|
||||
use MusicLibraryWeb, :html
|
||||
|
||||
def refresh_lastfm_feed_button(assigns) do
|
||||
~H"""
|
||||
<button
|
||||
type="button"
|
||||
class="phx-click-loading:animate-spin text-zinc-500 hover:text-zinc-900 dark:text-zinc-400 dark:hover:text-zinc-300"
|
||||
phx-click={JS.push("refresh_lastfm_feed")}
|
||||
>
|
||||
<span class="sr-only">{gettext("Refresh LastFm Feed")}</span>
|
||||
<.icon name="hero-arrow-path" class="-mt-1 h-5 w-5" aria-hidden="true" data-slot="icon" />
|
||||
</button>
|
||||
"""
|
||||
end
|
||||
end
|
||||
@@ -129,19 +129,6 @@ defmodule MusicLibraryWeb.StatsComponents do
|
||||
"""
|
||||
end
|
||||
|
||||
def refresh_lastfm_feed_button(assigns) do
|
||||
~H"""
|
||||
<button
|
||||
type="button"
|
||||
class="phx-click-loading:animate-spin text-zinc-500 hover:text-zinc-900 dark:text-zinc-400 dark:hover:text-zinc-300"
|
||||
phx-click={JS.push("refresh_lastfm_feed")}
|
||||
>
|
||||
<span class="sr-only">{gettext("Refresh LastFm Feed")}</span>
|
||||
<.icon name="hero-arrow-path" class="-mt-1 h-5 w-5" aria-hidden="true" data-slot="icon" />
|
||||
</button>
|
||||
"""
|
||||
end
|
||||
|
||||
attr :record_show_path, :any, required: true
|
||||
attr :records, :list, required: true
|
||||
attr :current_date, Date, required: true
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -293,7 +293,7 @@ msgstr ""
|
||||
msgid "MusicBrainz data refreshed successfully"
|
||||
msgstr ""
|
||||
|
||||
#: lib/music_library_web/components/stats_components.ex
|
||||
#: lib/music_library_web/components/scrobble_components.ex
|
||||
#, elixir-autogen, elixir-format
|
||||
msgid "Refresh LastFm Feed"
|
||||
msgstr ""
|
||||
|
||||
@@ -293,7 +293,7 @@ msgstr ""
|
||||
msgid "MusicBrainz data refreshed successfully"
|
||||
msgstr ""
|
||||
|
||||
#: lib/music_library_web/components/stats_components.ex
|
||||
#: lib/music_library_web/components/scrobble_components.ex
|
||||
#, elixir-autogen, elixir-format
|
||||
msgid "Refresh LastFm Feed"
|
||||
msgstr ""
|
||||
|
||||
Reference in New Issue
Block a user