diff --git a/pages/genre/genre.go b/pages/genre/genre.go index 312c8df0..e4ab127e 100644 --- a/pages/genre/genre.go +++ b/pages/genre/genre.go @@ -24,6 +24,7 @@ func Get(ctx *aero.Context) string { } userScore := averageScore(user, animes) + userCompleted := totalCompleted(user, animes) arn.SortAnimeByQuality(animes) @@ -31,7 +32,7 @@ func Get(ctx *aero.Context) string { animes = animes[:animePerPage] } - return ctx.HTML(components.Genre(genreName, animes, user, userScore)) + return ctx.HTML(components.Genre(genreName, animes, user, userScore, userCompleted)) } // containsLowerCase tells you whether the given element exists when all elements are lowercased. @@ -71,3 +72,24 @@ func averageScore(user *arn.User, animes []*arn.Anime) float64 { return scores / count } + +// totalCompleted counts the number of animes the user has completed from a given list of anime +func totalCompleted(user *arn.User, animes []*arn.Anime) int { + if user == nil { + return 0 + } + + count := 0 + + completedList := user.AnimeList().FilterStatus(arn.AnimeListStatusCompleted) + + for _, anime := range animes { + userAnime := completedList.Find(anime.ID) + + if userAnime != nil { + count++; + } + } + + return count; +} diff --git a/pages/genre/genre.pixy b/pages/genre/genre.pixy index c5e89b99..e92061c6 100644 --- a/pages/genre/genre.pixy +++ b/pages/genre/genre.pixy @@ -1,9 +1,9 @@ -component Genre(genre string, animes []*arn.Anime, user *arn.User, userScore float64) +component Genre(genre string, animes []*arn.Anime, user *arn.User, userScore float64, userCompleted int) h1(title=fmt.Sprint(len(animes)) + " anime")= strings.Title(genre) - .average-score + .average-score-total-completed if user != nil - p= fmt.Sprintf("Average Score: %.1f", userScore) + p= fmt.Sprintf("Average Score: %.1f | Total Completed: %d", userScore, userCompleted) .corner-buttons-hide-on-mobile if user != nil diff --git a/pages/genre/genre.scarlet b/pages/genre/genre.scarlet index 71f7a3be..254172df 100644 --- a/pages/genre/genre.scarlet +++ b/pages/genre/genre.scarlet @@ -1,2 +1,3 @@ -.average-score - text-align center \ No newline at end of file +.average-score-total-completed + text-align center + font-size 1.25em \ No newline at end of file