How to determine if the current page is the last or first page in Keyset pagination

I may be missing this from the documentation, but is there a way to find out if the current "page" is the firsrt or the last?
2 Replies
Jason
JasonOP2y ago
Looks like page.more? indicates false if the current page is the last one.
Blibs
Blibs2y ago
This is how I implemented that in my component:
defp assign_page_checks(socket, %{more?: more?, after: nil, before: nil}),
do: assign(socket, %{has_next?: more?, has_previous?: false})

defp assign_page_checks(socket, %{more?: more?, after: _, before: nil}),
do: assign(socket, %{has_next?: more?, has_previous?: true})

defp assign_page_checks(socket, %{more?: more?, after: nil, before: _}),
do: assign(socket, %{has_next?: true, has_previous?: more?})
defp assign_page_checks(socket, %{more?: more?, after: nil, before: nil}),
do: assign(socket, %{has_next?: more?, has_previous?: false})

defp assign_page_checks(socket, %{more?: more?, after: _, before: nil}),
do: assign(socket, %{has_next?: more?, has_previous?: true})

defp assign_page_checks(socket, %{more?: more?, after: nil, before: _}),
do: assign(socket, %{has_next?: true, has_previous?: more?})
Hopefully that can help

Did you find this page helpful?