feat: add pagination controls to admin post list
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
82feccf64a
commit
d7a5d425b8
|
|
@ -26,3 +26,12 @@ func (p PageInfo) PreviousPage() int {
|
||||||
func (p PageInfo) NextPage() int {
|
func (p PageInfo) NextPage() int {
|
||||||
return p.CurrentPage + 1
|
return p.CurrentPage + 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Pages returns a slice of page numbers for rendering numbered pagination.
|
||||||
|
func (p PageInfo) Pages() []int {
|
||||||
|
pages := make([]int, p.TotalPages)
|
||||||
|
for i := range pages {
|
||||||
|
pages[i] = i + 1
|
||||||
|
}
|
||||||
|
return pages
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -62,4 +62,22 @@
|
||||||
{{ end }}
|
{{ end }}
|
||||||
</div>
|
</div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
|
{{ if gt .pageInfo.TotalPages 1 }}
|
||||||
|
<nav aria-label="Page navigation" class="my-4">
|
||||||
|
<ul class="pagination justify-content-center">
|
||||||
|
<li class="page-item{{ if not .pageInfo.HasPrevious }} disabled{{ end }}">
|
||||||
|
<a class="page-link" href="?page={{ .pageInfo.PreviousPage }}{{ if .req.Filter }}&filter={{ .req.Filter }}{{ end }}">Previous</a>
|
||||||
|
</li>
|
||||||
|
{{ range $p := .pageInfo.Pages }}
|
||||||
|
<li class="page-item{{ if eq $p $.pageInfo.CurrentPage }} active{{ end }}">
|
||||||
|
<a class="page-link" href="?page={{ $p }}{{ if $.req.Filter }}&filter={{ $.req.Filter }}{{ end }}">{{ $p }}</a>
|
||||||
|
</li>
|
||||||
|
{{ end }}
|
||||||
|
<li class="page-item{{ if not .pageInfo.HasNext }} disabled{{ end }}">
|
||||||
|
<a class="page-link" href="?page={{ .pageInfo.NextPage }}{{ if .req.Filter }}&filter={{ .req.Filter }}{{ end }}">Next</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</nav>
|
||||||
|
{{ end }}
|
||||||
</main>
|
</main>
|
||||||
Loading…
Reference in a new issue