Improved video loading

This commit is contained in:
2018-04-15 11:14:11 +02:00
parent b6321de60b
commit d8714f92a2
7 changed files with 75 additions and 7 deletions

View File

@ -1,7 +1,10 @@
package amvs
import (
"sort"
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components"
"github.com/animenotifier/notify.moe/utils"
)
@ -10,12 +13,32 @@ import (
func Latest(ctx *aero.Context) string {
user := utils.GetUser(ctx)
return ctx.HTML(components.AMVs(nil, -1, "", user))
amvs := arn.FilterAMVs(func(amv *arn.AMV) bool {
return !amv.IsDraft
})
sort.Slice(amvs, func(i, j int) bool {
return amvs[i].Created > amvs[j].Created
})
return ctx.HTML(components.AMVs(amvs, -1, "", user))
}
// Best AMVs.
func Best(ctx *aero.Context) string {
user := utils.GetUser(ctx)
return ctx.HTML(components.AMVs(nil, -1, "", user))
amvs := arn.FilterAMVs(func(amv *arn.AMV) bool {
return !amv.IsDraft
})
sort.Slice(amvs, func(i, j int) bool {
if len(amvs[i].Likes) == len(amvs[j].Likes) {
return amvs[i].Title.String() < amvs[j].Title.String()
}
return len(amvs[i].Likes) > len(amvs[j].Likes)
})
return ctx.HTML(components.AMVs(amvs, -1, "", user))
}