43 lines
1001 B
Go
Raw Normal View History

2018-11-22 10:27:53 +09:00
package groups
import (
"github.com/aerogo/aero"
2019-06-03 18:32:43 +09:00
"github.com/animenotifier/notify.moe/arn"
2018-11-22 10:27:53 +09:00
"github.com/animenotifier/notify.moe/components"
"github.com/animenotifier/notify.moe/utils/infinitescroll"
)
const (
2018-11-22 11:51:44 +09:00
groupsFirstLoad = 27
groupsPerScroll = 18
2018-11-22 10:27:53 +09:00
)
// render renders the groups page with the given groups.
2019-06-01 13:55:49 +09:00
func render(ctx aero.Context, allGroups []*arn.Group) error {
2019-11-17 16:59:34 +09:00
user := arn.GetUserFromContext(ctx)
2018-11-22 10:27:53 +09:00
index, _ := ctx.GetInt("index")
// Slice the part that we need
groups := allGroups[index:]
maxLength := groupsFirstLoad
if index > 0 {
maxLength = groupsPerScroll
}
if len(groups) > maxLength {
groups = groups[:maxLength]
}
// Next index
nextIndex := infinitescroll.NextIndex(ctx, len(allGroups), maxLength, index)
// In case we're scrolling, send groups only (without the page frame)
if index > 0 {
return ctx.HTML(components.GroupsScrollable(groups, user))
}
// Otherwise, send the full page
return ctx.HTML(components.Groups(groups, nextIndex, user))
}