Added infinite scrolling to AMVs
This commit is contained in:
44
pages/amvs/render.go
Normal file
44
pages/amvs/render.go
Normal file
@ -0,0 +1,44 @@
|
||||
package amvs
|
||||
|
||||
import (
|
||||
"github.com/aerogo/aero"
|
||||
"github.com/animenotifier/arn"
|
||||
"github.com/animenotifier/notify.moe/components"
|
||||
"github.com/animenotifier/notify.moe/utils"
|
||||
"github.com/animenotifier/notify.moe/utils/infinitescroll"
|
||||
)
|
||||
|
||||
const (
|
||||
amvsFirstLoad = 12
|
||||
amvsPerScroll = 9
|
||||
)
|
||||
|
||||
// render renders the AMVs page with the given AMVs.
|
||||
func render(ctx *aero.Context, allAMVs []*arn.AMV) string {
|
||||
user := utils.GetUser(ctx)
|
||||
index, _ := ctx.GetInt("index")
|
||||
tag := ctx.Get("tag")
|
||||
|
||||
// Slice the part that we need
|
||||
amvs := allAMVs[index:]
|
||||
maxLength := amvsFirstLoad
|
||||
|
||||
if index > 0 {
|
||||
maxLength = amvsPerScroll
|
||||
}
|
||||
|
||||
if len(amvs) > maxLength {
|
||||
amvs = amvs[:maxLength]
|
||||
}
|
||||
|
||||
// Next index
|
||||
nextIndex := infinitescroll.NextIndex(ctx, len(allAMVs), maxLength, index)
|
||||
|
||||
// In case we're scrolling, send AMVs only (without the page frame)
|
||||
if index > 0 {
|
||||
return ctx.HTML(components.AMVsScrollable(amvs, user))
|
||||
}
|
||||
|
||||
// Otherwise, send the full page
|
||||
return ctx.HTML(components.AMVs(amvs, nextIndex, tag, user))
|
||||
}
|
Reference in New Issue
Block a user