Infinite scrolling for activities
This commit is contained in:
43
pages/activity/render.go
Normal file
43
pages/activity/render.go
Normal file
@ -0,0 +1,43 @@
|
||||
package activity
|
||||
|
||||
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 (
|
||||
activitiesFirstLoad = 40
|
||||
activitiesPerScroll = 20
|
||||
)
|
||||
|
||||
// render renders the activities page with the given activities.
|
||||
func render(ctx *aero.Context, allActivities []arn.Activity) string {
|
||||
user := utils.GetUser(ctx)
|
||||
index, _ := ctx.GetInt("index")
|
||||
|
||||
// Slice the part that we need
|
||||
activities := allActivities[index:]
|
||||
maxLength := activitiesFirstLoad
|
||||
|
||||
if index > 0 {
|
||||
maxLength = activitiesPerScroll
|
||||
}
|
||||
|
||||
if len(activities) > maxLength {
|
||||
activities = activities[:maxLength]
|
||||
}
|
||||
|
||||
// Next index
|
||||
nextIndex := infinitescroll.NextIndex(ctx, len(allActivities), maxLength, index)
|
||||
|
||||
// In case we're scrolling, send activities only (without the page frame)
|
||||
if index > 0 {
|
||||
return ctx.HTML(components.ActivitiesScrollable(activities, user))
|
||||
}
|
||||
|
||||
// Otherwise, send the full page
|
||||
return ctx.HTML(components.ActivityFeed(activities, nextIndex, user))
|
||||
}
|
Reference in New Issue
Block a user