45 lines
1.1 KiB
Go
Raw Normal View History

2018-04-22 15:43:20 +00:00
package characters
import (
"github.com/aerogo/aero"
2019-06-03 09:32:43 +00:00
"github.com/animenotifier/notify.moe/arn"
2018-04-22 15:43:20 +00:00
"github.com/animenotifier/notify.moe/components"
"github.com/animenotifier/notify.moe/utils"
"github.com/animenotifier/notify.moe/utils/infinitescroll"
)
const (
charactersFirstLoad = 104
charactersPerScroll = 39
)
// render renders the characters page with the given characters.
2019-06-01 04:55:49 +00:00
func render(ctx aero.Context, allCharacters []*arn.Character) error {
2018-04-22 15:43:20 +00:00
user := utils.GetUser(ctx)
index, _ := ctx.GetInt("index")
tag := ctx.Get("tag")
// Slice the part that we need
characters := allCharacters[index:]
maxLength := charactersFirstLoad
if index > 0 {
maxLength = charactersPerScroll
}
if len(characters) > maxLength {
characters = characters[:maxLength]
}
// Next index
nextIndex := infinitescroll.NextIndex(ctx, len(allCharacters), maxLength, index)
// In case we're scrolling, send Characters only (without the page frame)
if index > 0 {
return ctx.HTML(components.CharactersScrollable(characters, user))
}
// Otherwise, send the full page
return ctx.HTML(components.Characters(characters, nextIndex, tag, user))
}