From 60823564d4aeb82b5d6e92a3460e50f3208b88d3 Mon Sep 17 00:00:00 2001 From: David Vogel Date: Mon, 29 May 2023 14:32:25 +0200 Subject: [PATCH] Change PaginationBinder interface - Fix typo --- components/navigation/pagination-binder.go | 24 +++++++++++----------- components/navigation/pagination.go | 13 +++++++----- page-layout.go | 4 ++-- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/components/navigation/pagination-binder.go b/components/navigation/pagination-binder.go index 0127637..0d2883c 100644 --- a/components/navigation/pagination-binder.go +++ b/components/navigation/pagination-binder.go @@ -1,26 +1,26 @@ 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 { - Page() 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. - SetPage(page int) // SetPage changes 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. + PaginationPages() int // Pages returns the total number of pages. + 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. type PaginationInfo struct { - CurrentPage 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. + Page int // The current page as a 1-based index. A value of 0 means there is no current page. + Pages int // The number of total pages. } -func (p *PaginationInfo) Page() int { - return p.CurrentPage +func (p *PaginationInfo) PaginationPage() int { + return p.Page } -func (p *PaginationInfo) Pages() int { - return p.TotalPages +func (p *PaginationInfo) PaginationPages() int { + return p.Pages } -func (p *PaginationInfo) SetPage(page int) { - p.CurrentPage = page +func (p *PaginationInfo) SetPaginationPage(page int) { + p.Page = page } diff --git a/components/navigation/pagination.go b/components/navigation/pagination.go index 7a9a944..66ce102 100644 --- a/components/navigation/pagination.go +++ b/components/navigation/pagination.go @@ -20,20 +20,23 @@ type paginationButtonInfo struct { 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 { if c.Bind == nil { 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 { if c.Bind == nil { return 0 } - return c.Bind.Pages() + return c.Bind.PaginationPages() } func (c *Pagination) handleClickPrev(event input.ClickEvent) { @@ -52,15 +55,15 @@ func (c *Pagination) handleClickPage(event input.ClickEvent, page int) { } if c.Bind != nil { - c.Bind.SetPage(page) + c.Bind.SetPaginationPage(page) } if c.Paginate != nil { c.Paginate.PaginateHandle(PaginateEvent{ DOMEvent: event, PaginationInfo: PaginationInfo{ - CurrentPage: page, - TotalPages: pages, + Page: page, + Pages: pages, }, }) } diff --git a/page-layout.go b/page-layout.go index c273a95..fdd604e 100644 --- a/page-layout.go +++ b/page-layout.go @@ -12,8 +12,8 @@ type PageLayout struct { } func (c *PageLayout) Init(ctx vugu.InitCtx) { - c.Pagination.CurrentPage = 2 - c.Pagination.TotalPages = 10 + c.Pagination.Page = 2 + c.Pagination.Pages = 10 } func (c *PageLayout) handlePagination(event navigation.PaginateEvent) {