Skip to content

Commit

Permalink
paginator: fix switching to sequential pagination.
Browse files Browse the repository at this point in the history
Fix a bug where the paginator didn't correctly switch to sequential
pagination when reaching the page limit.
  • Loading branch information
evazion committed Feb 19, 2021
1 parent 4e6dff7 commit 981d56c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/components/paginator_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def initialize(records:, params:, window: 4)
end

def use_sequential_paginator?
paginator_mode != :numbered || current_page >= paginator_page_limit
paginator_mode != :numbered
end

def pages
Expand Down
6 changes: 5 additions & 1 deletion app/logical/pagination_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@ def paginate(page, limit: nil, max_limit: 1000, page_limit: CurrentUser.user.pag
elsif page.to_s =~ /\Aa(\d+)\z/i
@paginator_mode = :sequential_after
paginate_sequential_after($1, records_per_page)
elsif page.to_i > page_limit
raise PaginationError
elsif page.to_i == page_limit
@paginator_mode = :sequential_after
paginate_numbered(page.to_i, records_per_page)
else
@paginator_mode = :numbered
@current_page = [page.to_i, 1].max
raise PaginationError if current_page > page_limit

paginate_numbered(current_page, records_per_page)
end
Expand Down

0 comments on commit 981d56c

Please sign in to comment.