40 lines
1012 B
Go
40 lines
1012 B
Go
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"
|
|
)
|
|
|
|
// Best renders the best soundtracks.
|
|
func Best(ctx *aero.Context) string {
|
|
user := utils.GetUser(ctx)
|
|
index, _ := ctx.GetInt("index")
|
|
|
|
// Fetch all eligible tracks
|
|
allTracks := fetchAll()
|
|
|
|
// Sort the tracks by number of likes
|
|
arn.SortSoundTracksPopularFirst(allTracks)
|
|
|
|
// Slice the part that we need
|
|
tracks := allTracks[index:]
|
|
|
|
if len(tracks) > maxTracks {
|
|
tracks = tracks[:maxTracks]
|
|
}
|
|
|
|
// Next index
|
|
nextIndex := infinitescroll.NextIndex(ctx, len(allTracks), maxTracks, 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))
|
|
}
|