Show sequels of completed anime

This commit is contained in:
2018-03-26 23:38:15 +02:00
parent 516b4a1966
commit ca90d40ca9
6 changed files with 104 additions and 7 deletions

View File

@ -1,4 +1,4 @@
component ExploreAnime(animeList []*arn.Anime, year string, status string, typ string, user *arn.User)
component ExploreAnime(animes []*arn.Anime, year string, status string, typ string, user *arn.User)
#filter-root(data-url="/explore/anime")
ExploreFilters(year, status, typ, false)
@ -7,6 +7,10 @@ component ExploreAnime(animeList []*arn.Anime, year string, status string, typ s
button.action(data-trigger="click", data-action="hideAddedAnime", title="Hide anime in my collection")
RawIcon("eye-slash")
if user != nil
a.button(href="/explore/sequels", title="View sequels of my completed anime")
RawIcon("forward")
a.button(href="/explore/color/any/anime", title="View colors")
RawIcon("paint-brush")
@ -16,10 +20,10 @@ component ExploreAnime(animeList []*arn.Anime, year string, status string, typ s
h1.page-title Explore
.explore-anime
if len(animeList) == 0
if len(animes) == 0
p.no-data.mountable No anime found using the above filters.
else
AnimeGrid(animeList, user)
AnimeGrid(animes, user)
component ExploreFilters(year string, status string, typ string, advancedFilters bool)
.explore-filters

View File

@ -0,0 +1,8 @@
component ExploreAnimeSequels(entries []*utils.AnimeWithRelatedAnime, user *arn.User)
h1 Sequels of my completed anime
.explore-anime
if len(entries) == 0
p.no-data.mountable No sequels found for the anime you completed.
else
AnimeGridWithRelation(entries, user)

View File

@ -0,0 +1,57 @@
package explorerelations
import (
"net/http"
"sort"
"github.com/animenotifier/arn"
"github.com/aerogo/aero"
"github.com/animenotifier/notify.moe/components"
"github.com/animenotifier/notify.moe/utils"
)
// Sequels ...
func Sequels(ctx *aero.Context) string {
user := utils.GetUser(ctx)
if user == nil {
return ctx.Error(http.StatusUnauthorized, "Not logged in", nil)
}
animeList := user.AnimeList()
sequels := []*utils.AnimeWithRelatedAnime{}
for anime := range arn.StreamAnime() {
if animeList.Contains(anime.ID) {
continue
}
prequels := anime.Prequels()
for _, prequel := range prequels {
item := animeList.Find(prequel.ID)
if item != nil && item.Status == arn.AnimeListStatusCompleted {
sequels = append(sequels, &utils.AnimeWithRelatedAnime{
Anime: anime,
Related: prequel,
})
break
}
}
}
sort.Slice(sequels, func(i, j int) bool {
aScore := sequels[i].Anime.Score()
bScore := sequels[j].Anime.Score()
if aScore == bScore {
return sequels[i].Anime.Title.Canonical < sequels[j].Anime.Title.Canonical
}
return aScore > bScore
})
return ctx.HTML(components.ExploreAnimeSequels(sequels, user))
}

View File

@ -28,6 +28,7 @@ import (
"github.com/animenotifier/notify.moe/pages/episode"
"github.com/animenotifier/notify.moe/pages/explore"
"github.com/animenotifier/notify.moe/pages/explore/explorecolor"
"github.com/animenotifier/notify.moe/pages/explore/explorerelations"
"github.com/animenotifier/notify.moe/pages/forum"
"github.com/animenotifier/notify.moe/pages/genre"
"github.com/animenotifier/notify.moe/pages/genres"
@ -79,6 +80,7 @@ func Configure(app *aero.Application) {
l.Page("/explore/anime/:year/:status/:type", explore.Filter)
l.Page("/explore/color/:color/anime", explorecolor.AnimeByAverageColor)
l.Page("/explore/color/:color/anime/from/:index", explorecolor.AnimeByAverageColor)
l.Page("/explore/sequels", explorerelations.Sequels)
l.Page("/login", login.Get)
l.Page("/api", apiview.Get)
// l.Ajax("/dashboard", dashboard.Get)