Rewritten infinite scrolling

This commit is contained in:
2018-03-13 22:38:26 +01:00
parent 663070cf2a
commit 3e2594ab9f
10 changed files with 108 additions and 189 deletions

View File

@ -0,0 +1,21 @@
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
}