Stabilize realtime discovery pagination
This commit is contained in:
parent
741359e476
commit
ea2a1b6f5e
|
|
@ -68,21 +68,6 @@ defmodule WhoNeedHelpWeb.ActivityLive.Index do
|
||||||
user_id = socket.assigns.current_scope.user.id
|
user_id = socket.assigns.current_scope.user.id
|
||||||
already_mine? = Enum.any?(socket.assigns.my_activities, &(&1.id == activity.id))
|
already_mine? = Enum.any?(socket.assigns.my_activities, &(&1.id == activity.id))
|
||||||
|
|
||||||
{activities, activities_cursor} =
|
|
||||||
update_entry(
|
|
||||||
socket.assigns.activities,
|
|
||||||
activity,
|
|
||||||
not is_nil(socket.assigns.viewport) and
|
|
||||||
Activities.visible_open_activity?(
|
|
||||||
socket.assigns.current_scope,
|
|
||||||
activity,
|
|
||||||
socket.assigns.filters,
|
|
||||||
socket.assigns.viewport
|
|
||||||
),
|
|
||||||
:asc,
|
|
||||||
socket.assigns.activities_cursor
|
|
||||||
)
|
|
||||||
|
|
||||||
{my_activities, my_activities_cursor} =
|
{my_activities, my_activities_cursor} =
|
||||||
update_entry(
|
update_entry(
|
||||||
socket.assigns.my_activities,
|
socket.assigns.my_activities,
|
||||||
|
|
@ -94,12 +79,14 @@ defmodule WhoNeedHelpWeb.ActivityLive.Index do
|
||||||
|
|
||||||
socket =
|
socket =
|
||||||
socket
|
socket
|
||||||
|> assign(:activities, activities)
|
|
||||||
|> assign(:activities_cursor, activities_cursor)
|
|
||||||
|> assign(:my_activities, my_activities)
|
|> assign(:my_activities, my_activities)
|
||||||
|> assign(:my_activities_cursor, my_activities_cursor)
|
|> assign(:my_activities_cursor, my_activities_cursor)
|
||||||
|
|
||||||
if socket.assigns.refresh_timer || socket.assigns.view_mode == "list" do
|
# A single authoritative page reload keeps the list, cursor, result count,
|
||||||
|
# and map clusters on the same database snapshot. Applying the PubSub item
|
||||||
|
# locally and then accepting an in-flight async page allowed an older page
|
||||||
|
# to overwrite a newer bounded window during bursts.
|
||||||
|
if socket.assigns.refresh_timer do
|
||||||
{:noreply, socket}
|
{:noreply, socket}
|
||||||
else
|
else
|
||||||
timer = Process.send_after(self(), :refresh_discovery, 100)
|
timer = Process.send_after(self(), :refresh_discovery, 100)
|
||||||
|
|
|
||||||
|
|
@ -665,7 +665,11 @@ defmodule WhoNeedHelpWeb.MutualAidLiveTest do
|
||||||
first = List.first(requests)
|
first = List.first(requests)
|
||||||
overflow = List.last(requests)
|
overflow = List.last(requests)
|
||||||
|
|
||||||
assert_eventually(fn -> has_element?(view, "#open-request-#{first.id}") end)
|
assert_eventually(fn ->
|
||||||
|
has_element?(view, "#open-request-#{first.id}") and
|
||||||
|
has_element?(view, "button", "Load more in this area")
|
||||||
|
end)
|
||||||
|
|
||||||
refute has_element?(view, "#open-request-#{overflow.id}")
|
refute has_element?(view, "#open-request-#{overflow.id}")
|
||||||
|
|
||||||
view |> element("button", "Load more in this area") |> render_click()
|
view |> element("button", "Load more in this area") |> render_click()
|
||||||
|
|
@ -704,7 +708,7 @@ defmodule WhoNeedHelpWeb.MutualAidLiveTest do
|
||||||
"safety_confirmed" => true
|
"safety_confirmed" => true
|
||||||
})
|
})
|
||||||
|
|
||||||
assert render(view) =~ "Realtime coffee meetup"
|
assert_eventually(fn -> render(view) =~ "Realtime coffee meetup" end)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "activity realtime updates keep a bounded window without skipping pagination" do
|
test "activity realtime updates keep a bounded window without skipping pagination" do
|
||||||
|
|
@ -738,11 +742,14 @@ defmodule WhoNeedHelpWeb.MutualAidLiveTest do
|
||||||
activity
|
activity
|
||||||
end
|
end
|
||||||
|
|
||||||
render(view)
|
|
||||||
first = List.first(activities)
|
first = List.first(activities)
|
||||||
overflow = List.last(activities)
|
overflow = List.last(activities)
|
||||||
|
|
||||||
assert has_element?(view, "#open-activity-#{first.id}")
|
assert_eventually(fn ->
|
||||||
|
has_element?(view, "#open-activity-#{first.id}") and
|
||||||
|
has_element?(view, "button", "Load more")
|
||||||
|
end)
|
||||||
|
|
||||||
refute has_element?(view, "#open-activity-#{overflow.id}")
|
refute has_element?(view, "#open-activity-#{overflow.id}")
|
||||||
|
|
||||||
view |> element("button", "Load more") |> render_click()
|
view |> element("button", "Load more") |> render_click()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user