From 149579d584e4b6e64a393aec2e7b19a47536558b Mon Sep 17 00:00:00 2001 From: Christian Rocha Date: Fri, 15 May 2020 13:24:32 -0400 Subject: [PATCH] Add helper method to paginator for determining if we're on the last page --- paginator/paginator.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/paginator/paginator.go b/paginator/paginator.go index 3583593..9aff3b7 100644 --- a/paginator/paginator.go +++ b/paginator/paginator.go @@ -82,11 +82,19 @@ func (m *Model) PrevPage() { // NextPage is a helper function for navigating one page forward. It will not // page beyond the last page (i.e. totalPages - 1). func (m *Model) NextPage() { - if m.Page < m.TotalPages-1 { + if !m.OnLastPage() { m.Page++ } } +// LastPage returns whether or not we're on the last page +func (m Model) OnLastPage() bool { + if m.Page == m.TotalPages-1 { + return true + } + return false +} + // NewModel creates a new model with defaults func NewModel() Model { return Model{