feat: add pagination controls to admin post list

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Leon Mika 2026-03-22 14:34:55 +11:00
parent 82feccf64a
commit d7a5d425b8
2 changed files with 27 additions and 0 deletions

View file

@ -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
}

View file

@ -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>