Skip to content

Commit

Permalink
fix: ensure next page is detected for offset pages w/ more?: true
Browse files Browse the repository at this point in the history
  • Loading branch information
zachdaniel committed Dec 19, 2023
1 parent 0026d16 commit 78b80b3
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions lib/ash_phoenix/live_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ defmodule AshPhoenix.LiveView do

def page_link_params(%Ash.Page.Offset{more?: false}, "next"), do: :invalid

def page_link_params(%Ash.Page.Offset{more?: true} = offset, "next") do
[limit: offset.limit, offset: (offset.offset || 0) + offset.limit]
end

def page_link_params(%Ash.Page.Keyset{more?: false, after: nil, before: before}, "prev")
when not is_nil(before) do
:invalid
Expand All @@ -309,19 +313,6 @@ defmodule AshPhoenix.LiveView do
:invalid
end

def page_link_params(%Ash.Page.Offset{} = offset, "next") do
cond do
offset.count && offset.offset + offset.limit >= offset.count ->
:invalid

Enum.count(offset.results) < offset.limit ->
:invalid

true ->
[limit: offset.limit, offset: (offset.offset || 0) + offset.limit]
end
end

def page_link_params(%Ash.Page.Offset{offset: 0}, "prev") do
:invalid
end
Expand Down

0 comments on commit 78b80b3

Please sign in to comment.