2018-03-14 17:07:58 +00:00
|
|
|
package soundtracks
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/aerogo/aero"
|
2019-06-03 09:32:43 +00:00
|
|
|
"github.com/animenotifier/notify.moe/arn"
|
2018-03-14 17:07:58 +00:00
|
|
|
"github.com/animenotifier/notify.moe/components"
|
|
|
|
"github.com/animenotifier/notify.moe/utils/infinitescroll"
|
|
|
|
)
|
|
|
|
|
2018-03-14 17:10:21 +00:00
|
|
|
const (
|
|
|
|
tracksFirstLoad = 12
|
2018-03-14 20:01:27 +00:00
|
|
|
tracksPerScroll = 9
|
2018-03-14 17:10:21 +00:00
|
|
|
)
|
|
|
|
|
2018-03-14 17:07:58 +00:00
|
|
|
// render renders the soundracks page with the given tracks.
|
2019-06-01 04:55:49 +00:00
|
|
|
func render(ctx aero.Context, allTracks []*arn.SoundTrack) error {
|
2019-11-17 07:59:34 +00:00
|
|
|
user := arn.GetUserFromContext(ctx)
|
2018-03-14 17:07:58 +00:00
|
|
|
index, _ := ctx.GetInt("index")
|
2018-03-15 15:57:39 +00:00
|
|
|
tag := ctx.Get("tag")
|
2018-03-14 17:07:58 +00:00
|
|
|
|
|
|
|
// Slice the part that we need
|
|
|
|
tracks := allTracks[index:]
|
|
|
|
maxLength := tracksFirstLoad
|
|
|
|
|
|
|
|
if index > 0 {
|
|
|
|
maxLength = tracksPerScroll
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(tracks) > maxLength {
|
|
|
|
tracks = tracks[:maxLength]
|
|
|
|
}
|
|
|
|
|
|
|
|
// Next index
|
|
|
|
nextIndex := infinitescroll.NextIndex(ctx, len(allTracks), maxLength, index)
|
|
|
|
|
|
|
|
// In case we're scrolling, send soundtracks only (without the page frame)
|
|
|
|
if index > 0 {
|
|
|
|
return ctx.HTML(components.SoundTracksScrollable(tracks, user))
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, send the full page
|
2018-03-15 15:57:39 +00:00
|
|
|
return ctx.HTML(components.SoundTracks(tracks, nextIndex, tag, user))
|
2018-03-14 17:07:58 +00:00
|
|
|
}
|