2018-11-12 06:05:46 +00:00
|
|
|
package activity
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/aerogo/aero"
|
2019-06-03 09:32:43 +00:00
|
|
|
"github.com/animenotifier/notify.moe/arn"
|
2018-11-12 06:05:46 +00:00
|
|
|
"github.com/animenotifier/notify.moe/components"
|
|
|
|
"github.com/animenotifier/notify.moe/utils/infinitescroll"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
activitiesFirstLoad = 40
|
|
|
|
activitiesPerScroll = 20
|
|
|
|
)
|
|
|
|
|
|
|
|
// render renders the activities page with the given activities.
|
2019-06-01 04:55:49 +00:00
|
|
|
func render(ctx aero.Context, allActivities []arn.Activity) error {
|
2019-11-17 07:59:34 +00:00
|
|
|
user := arn.GetUserFromContext(ctx)
|
2018-11-12 06:05:46 +00:00
|
|
|
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))
|
|
|
|
}
|