Abstracted soundtracks code (less code now)
This commit is contained in:
38
pages/soundtracks/render.go
Normal file
38
pages/soundtracks/render.go
Normal file
@ -0,0 +1,38 @@
|
||||
package soundtracks
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
// render renders the soundracks page with the given tracks.
|
||||
func render(ctx *aero.Context, allTracks []*arn.SoundTrack) string {
|
||||
user := utils.GetUser(ctx)
|
||||
index, _ := ctx.GetInt("index")
|
||||
|
||||
// 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
|
||||
return ctx.HTML(components.SoundTracks(tracks, nextIndex, "", user))
|
||||
}
|
Reference in New Issue
Block a user