Rewritten infinite scrolling
This commit is contained in:
21
utils/infinitescroll/NextIndex.go
Normal file
21
utils/infinitescroll/NextIndex.go
Normal 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
|
||||
}
|
Reference in New Issue
Block a user