Implemented new frontpage

This commit is contained in:
2017-09-22 17:23:22 +02:00
parent 9c900ec01b
commit 4ce0bed52c
7 changed files with 70 additions and 30 deletions

39
pages/home/animelist.go Normal file
View File

@ -0,0 +1,39 @@
package home
import (
"net/http"
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components"
"github.com/animenotifier/notify.moe/pages/frontpage"
"github.com/animenotifier/notify.moe/utils"
)
// FilterByStatus returns a handler for the given anime list item status.
func FilterByStatus(status string) aero.Handle {
return func(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil {
return frontpage.Get(ctx)
}
return AnimeList(ctx, user, status)
}
}
// AnimeList sends the anime list with the given status for given user.
func AnimeList(ctx *aero.Context, user *arn.User, status string) string {
viewUser := user
animeList := viewUser.AnimeList()
if animeList == nil {
return ctx.Error(http.StatusNotFound, "Anime list not found", nil)
}
animeList.PrefetchAnime()
animeList.Sort()
return ctx.HTML(components.Home(animeList.FilterStatus(status), viewUser, user, status))
}