Add helper method to paginator for determining if we're on the last page

This commit is contained in:
Christian Rocha 2020-05-15 13:24:32 -04:00
parent 5a1ee26a6b
commit 149579d584
No known key found for this signature in database
GPG Key ID: D6CC7A16E5878018
1 changed files with 9 additions and 1 deletions

View File

@ -82,11 +82,19 @@ func (m *Model) PrevPage() {
// NextPage is a helper function for navigating one page forward. It will not // NextPage is a helper function for navigating one page forward. It will not
// page beyond the last page (i.e. totalPages - 1). // page beyond the last page (i.e. totalPages - 1).
func (m *Model) NextPage() { func (m *Model) NextPage() {
if m.Page < m.TotalPages-1 { if !m.OnLastPage() {
m.Page++ 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 // NewModel creates a new model with defaults
func NewModel() Model { func NewModel() Model {
return Model{ return Model{