Change PaginationBinder interface

- Fix typo
This commit is contained in:
David Vogel 2023-05-29 14:32:25 +02:00
parent c149bbfc06
commit 60823564d4
3 changed files with 22 additions and 19 deletions

View File

@ -1,26 +1,26 @@
package navigation package navigation
// PaginationBinder is an interface that everything that every type that wants to bind to an pagination component must implement. // PaginationBinder is an interface that everything that every type that wants to bind to a pagination component must implement.
type PaginationBinder interface { type PaginationBinder interface {
Page() int // Page returns the current page, as a 1-based index. A value of 0 means there is no active page. PaginationPage() int // Page returns the current page, as a 1-based index. A value of 0 means there is no active page.
Pages() int // Pages returns the total number of pages. PaginationPages() int // Pages returns the total number of pages.
SetPage(page int) // SetPage changes the current page as a 1-based index. A value of 0 means there is no active page. SetPaginationPage(page int) // SetPage changes the current page as a 1-based index. A value of 0 means there is no active page.
} }
// PaginationInfo implements the PaginationBinder interface and represents the current state of a pagination component. // PaginationInfo implements the PaginationBinder interface and represents the current state of a pagination component.
type PaginationInfo struct { type PaginationInfo struct {
CurrentPage int // The current page as a 1-based index. A value of 0 means there is no current page. Page int // The current page as a 1-based index. A value of 0 means there is no current page.
TotalPages int // The number of total pages. Pages int // The number of total pages.
} }
func (p *PaginationInfo) Page() int { func (p *PaginationInfo) PaginationPage() int {
return p.CurrentPage return p.Page
} }
func (p *PaginationInfo) Pages() int { func (p *PaginationInfo) PaginationPages() int {
return p.TotalPages return p.Pages
} }
func (p *PaginationInfo) SetPage(page int) { func (p *PaginationInfo) SetPaginationPage(page int) {
p.CurrentPage = page p.Page = page
} }

View File

@ -20,20 +20,23 @@ type paginationButtonInfo struct {
Class string Class string
} }
// Page returns the currently selected page as a 1-based index.
// A result of 0 means there is no selected page.
func (c *Pagination) Page() int { func (c *Pagination) Page() int {
if c.Bind == nil { if c.Bind == nil {
return 0 return 0
} }
return c.Bind.Page() return c.Bind.PaginationPage()
} }
// Pages returns the total page number that this pagination component shows.
func (c *Pagination) Pages() int { func (c *Pagination) Pages() int {
if c.Bind == nil { if c.Bind == nil {
return 0 return 0
} }
return c.Bind.Pages() return c.Bind.PaginationPages()
} }
func (c *Pagination) handleClickPrev(event input.ClickEvent) { func (c *Pagination) handleClickPrev(event input.ClickEvent) {
@ -52,15 +55,15 @@ func (c *Pagination) handleClickPage(event input.ClickEvent, page int) {
} }
if c.Bind != nil { if c.Bind != nil {
c.Bind.SetPage(page) c.Bind.SetPaginationPage(page)
} }
if c.Paginate != nil { if c.Paginate != nil {
c.Paginate.PaginateHandle(PaginateEvent{ c.Paginate.PaginateHandle(PaginateEvent{
DOMEvent: event, DOMEvent: event,
PaginationInfo: PaginationInfo{ PaginationInfo: PaginationInfo{
CurrentPage: page, Page: page,
TotalPages: pages, Pages: pages,
}, },
}) })
} }

View File

@ -12,8 +12,8 @@ type PageLayout struct {
} }
func (c *PageLayout) Init(ctx vugu.InitCtx) { func (c *PageLayout) Init(ctx vugu.InitCtx) {
c.Pagination.CurrentPage = 2 c.Pagination.Page = 2
c.Pagination.TotalPages = 10 c.Pagination.Pages = 10
} }
func (c *PageLayout) handlePagination(event navigation.PaginateEvent) { func (c *PageLayout) handlePagination(event navigation.PaginateEvent) {