22 lines
466 B
Go
Raw 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
func NextIndex(ctx *aero.Context, allElementsLength int, elementsPerScroll int, index int) int {
nextIndex := index + elementsPerScroll
if nextIndex >= allElementsLength {
nextIndex = -1
}
// Send the index for the next request
ctx.Response().Header().Set("X-LoadMore-Index", strconv.Itoa(nextIndex))
return nextIndex
}