Show sequels of completed anime

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

View File

@ -2,14 +2,31 @@ component AnimeGrid(animes []*arn.Anime, user *arn.User)
#load-more-target.anime-grid
AnimeGridScrollable(animes, user)
component AnimeGridWithRelation(entries []*utils.AnimeWithRelatedAnime, user *arn.User)
#load-more-target.anime-grid
AnimeGridWithRelationScrollable(entries, user)
component AnimeGridScrollable(animes []*arn.Anime, user *arn.User)
each anime in animes
.anime-grid-cell(data-added=(user != nil && user.AnimeList().Contains(anime.ID)))
a(href="/anime/" + toString(anime.ID))
a(href="/anime/" + anime.ID)
img.anime-grid-image.lazy(data-src=anime.ImageLink("medium"), data-webp="true", data-color=anime.AverageColor(), alt=anime.Title.Romaji)
.anime-grid-title
.anime-grid-title-text= anime.Title.ByUser(user)
if user != nil && !user.AnimeList().Contains(anime.ID)
button.anime-grid-add-button.action(data-action="addAnimeToCollection", data-trigger="click", data-api="/api/animelist/" + user.ID, data-anime-id=anime.ID)
RawIcon("plus")
AnimeGridButton(anime, user)
component AnimeGridWithRelationScrollable(entries []*utils.AnimeWithRelatedAnime, user *arn.User)
each entry in entries
.anime-grid-cell(data-added=(user != nil && user.AnimeList().Contains(entry.Anime.ID)))
a(href="/anime/" + entry.Anime.ID)
img.anime-grid-image.lazy(data-src=entry.Anime.ImageLink("medium"), data-webp="true", data-color=entry.Anime.AverageColor(), alt=entry.Anime.Title.Romaji)
.anime-grid-title
.anime-grid-title-text= entry.Anime.Title.ByUser(user)
AnimeGridButton(entry.Anime, user)
component AnimeGridButton(anime *arn.Anime, user *arn.User)
if user != nil && !user.AnimeList().Contains(anime.ID)
button.anime-grid-add-button.action(data-action="addAnimeToCollection", data-trigger="click", data-api="/api/animelist/" + user.ID, data-anime-id=anime.ID)
RawIcon("plus")

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)

View File

@ -0,0 +1,9 @@
package utils
import "github.com/animenotifier/arn"
// AnimeWithRelatedAnime ...
type AnimeWithRelatedAnime struct {
Anime *arn.Anime
Related *arn.Anime
}