44 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/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 {
2019-11-17 07:59:34 +00:00
user := arn.GetUserFromContext(ctx)
2018-04-22 15:43:20 +00:00
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))
}