Don't use streams for records on this day
This commit is contained in:
@@ -150,8 +150,7 @@ defmodule MusicLibraryWeb.StatsComponents do
|
|||||||
<ul
|
<ul
|
||||||
class="mt-5 p-4"
|
class="mt-5 p-4"
|
||||||
role="list"
|
role="list"
|
||||||
id="records"
|
id="records-on-this-day"
|
||||||
phx-update="stream"
|
|
||||||
>
|
>
|
||||||
<li
|
<li
|
||||||
id="no-records-on-this-day"
|
id="no-records-on-this-day"
|
||||||
@@ -160,10 +159,10 @@ defmodule MusicLibraryWeb.StatsComponents do
|
|||||||
{gettext("No records released on this day.")}
|
{gettext("No records released on this day.")}
|
||||||
</li>
|
</li>
|
||||||
<li
|
<li
|
||||||
:for={{id, record} <- @records}
|
:for={record <- @records}
|
||||||
phx-click={JS.navigate(@record_show_path.(record))}
|
phx-click={JS.navigate(@record_show_path.(record))}
|
||||||
class="flex justify-between gap-x-6 py-2 hover:bg-zinc-50 dark:hover:bg-zinc-800 px-2 -mx-2 md:px-4 md:-mx-4 cursor-pointer"
|
class="flex justify-between gap-x-6 py-2 hover:bg-zinc-50 dark:hover:bg-zinc-800 px-2 -mx-2 md:px-4 md:-mx-4 cursor-pointer"
|
||||||
id={id}
|
id={record.id}
|
||||||
>
|
>
|
||||||
<div class="flex min-w-0 gap-x-4 items-center">
|
<div class="flex min-w-0 gap-x-4 items-center">
|
||||||
<div class="relative w-12 flex-none">
|
<div class="relative w-12 flex-none">
|
||||||
|
|||||||
@@ -30,7 +30,6 @@ defmodule MusicLibraryWeb.StatsLive.Index do
|
|||||||
|> stream_configure(:recent_albums,
|
|> stream_configure(:recent_albums,
|
||||||
dom_id: fn %{album: album} -> "album-#{album.scrobbled_at_uts}" end
|
dom_id: fn %{album: album} -> "album-#{album.scrobbled_at_uts}" end
|
||||||
)
|
)
|
||||||
|> stream(:records_on_this_day, records_on_this_day, reset: true)
|
|
||||||
|> assign_counts()
|
|> assign_counts()
|
||||||
|> assign_scrobble_activity()
|
|> assign_scrobble_activity()
|
||||||
|> assign(
|
|> assign(
|
||||||
@@ -40,7 +39,8 @@ defmodule MusicLibraryWeb.StatsLive.Index do
|
|||||||
page_title: gettext("Stats"),
|
page_title: gettext("Stats"),
|
||||||
current_section: :stats,
|
current_section: :stats,
|
||||||
records_by_artist: records_by_artists,
|
records_by_artist: records_by_artists,
|
||||||
records_by_genre: records_by_genre
|
records_by_genre: records_by_genre,
|
||||||
|
records_on_this_day: records_on_this_day
|
||||||
)}
|
)}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -89,8 +89,7 @@ defmodule MusicLibraryWeb.StatsLive.Index do
|
|||||||
|
|
||||||
{:noreply,
|
{:noreply,
|
||||||
socket
|
socket
|
||||||
|> assign(:current_date, date)
|
|> assign(%{current_date: date, records_on_this_day: records_on_this_day})}
|
||||||
|> stream(:records_on_this_day, records_on_this_day, reset: true)}
|
|
||||||
|
|
||||||
{:error, _reason} ->
|
{:error, _reason} ->
|
||||||
{:noreply, socket}
|
{:noreply, socket}
|
||||||
|
|||||||
@@ -510,7 +510,7 @@
|
|||||||
<div class="bg-white dark:bg-zinc-800 rounded-md shadow-sm">
|
<div class="bg-white dark:bg-zinc-800 rounded-md shadow-sm">
|
||||||
<.records_on_this_day
|
<.records_on_this_day
|
||||||
current_date={@current_date}
|
current_date={@current_date}
|
||||||
records={@streams.records_on_this_day}
|
records={@records_on_this_day}
|
||||||
record_show_path={fn record -> ~p"/collection/#{record}" end}
|
record_show_path={fn record -> ~p"/collection/#{record}" end}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -269,13 +269,9 @@ defmodule MusicLibraryWeb.StatsLive.IndexTest do
|
|||||||
|
|
||||||
assert_has(session, "h1", text: "On This day")
|
assert_has(session, "h1", text: "On This day")
|
||||||
|
|
||||||
assert_has(session, "#records_on_this_day-#{record_today.id} h2",
|
assert_has(session, "##{record_today.id} h2", text: escape(record_today.title))
|
||||||
text: escape(record_today.title)
|
|
||||||
)
|
|
||||||
|
|
||||||
refute_has(session, "#records_on_this_day-#{record_yesterday.id} h2",
|
refute_has(session, "##{record_yesterday.id} h2", text: escape(record_yesterday.title))
|
||||||
text: escape(record_yesterday.title)
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it updates the 'On This Day' records when the date is changed", %{
|
test "it updates the 'On This Day' records when the date is changed", %{
|
||||||
@@ -303,13 +299,9 @@ defmodule MusicLibraryWeb.StatsLive.IndexTest do
|
|||||||
|
|
||||||
session = conn |> visit("/")
|
session = conn |> visit("/")
|
||||||
|
|
||||||
assert_has(session, "#records_on_this_day-#{record_today.id} h2",
|
assert_has(session, "##{record_today.id} h2", text: escape(record_today.title))
|
||||||
text: escape(record_today.title)
|
|
||||||
)
|
|
||||||
|
|
||||||
refute_has(session, "#records_on_this_day-#{record_yesterday.id} h2",
|
refute_has(session, "##{record_yesterday.id} h2", text: escape(record_yesterday.title))
|
||||||
text: escape(record_yesterday.title)
|
|
||||||
)
|
|
||||||
|
|
||||||
session
|
session
|
||||||
|> unwrap(fn view ->
|
|> unwrap(fn view ->
|
||||||
@@ -318,13 +310,9 @@ defmodule MusicLibraryWeb.StatsLive.IndexTest do
|
|||||||
|> render_change()
|
|> render_change()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
refute_has(session, "#records_on_this_day-#{record_today.id} h2",
|
refute_has(session, "##{record_today.id} h2", text: escape(record_today.title))
|
||||||
text: escape(record_today.title)
|
|
||||||
)
|
|
||||||
|
|
||||||
assert_has(session, "#records_on_this_day-#{record_yesterday.id} h2",
|
assert_has(session, "##{record_yesterday.id} h2", text: escape(record_yesterday.title))
|
||||||
text: escape(record_yesterday.title)
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user