Skip to content

Commit

Permalink
Fix out-of-bounds page nav buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
patapancakes committed Jul 21, 2024
1 parent 560b157 commit 0063b20
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion ingame/browser/browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,17 @@ func Handle(w http.ResponseWriter, r *http.Request) {

body += "</div>"

body += fmt.Sprintf(`<div class="pagenav"><a href="?page=%d">Previous</a>%d<a href="?page=%d">Next</a></div>`, page-1, page, page+1)
previous := fmt.Sprintf("?page=%d", page-1)
if page <= 1 {
previous = "#"
}

next := fmt.Sprintf("?page=%d", page+1)
if len(list) < itemsPerPage {
next = "#"
}

body += fmt.Sprintf(`<div class="pagenav"><a href="%s">Previous</a>%d<a href="%s">Next</a></div>`, previous, page, next)

body += "</html>"

Expand Down

0 comments on commit 0063b20

Please sign in to comment.