22 lines
462 B
Go
Raw Permalink Normal View History

2018-03-13 21:38:26 +00:00
package infinitescroll
import (
"strconv"
"github.com/aerogo/aero"
)
// NextIndex calculates the next index and sends HTTP header
2019-06-01 04:55:49 +00:00
func NextIndex(ctx aero.Context, allElementsLength int, elementsPerScroll int, index int) int {
2018-03-13 21:38:26 +00:00
nextIndex := index + elementsPerScroll
if nextIndex >= allElementsLength {
nextIndex = -1
}
// Send the index for the next request
2019-06-01 04:55:49 +00:00
ctx.Response().SetHeader("X-LoadMore-Index", strconv.Itoa(nextIndex))
2018-03-13 21:38:26 +00:00
return nextIndex
}