Add functionality to display the total number of anime a user has completed for a genre on its page
This commit is contained in:
parent
6a83042953
commit
f94a5d3d8b
@ -24,6 +24,7 @@ func Get(ctx *aero.Context) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
userScore := averageScore(user, animes)
|
userScore := averageScore(user, animes)
|
||||||
|
userCompleted := totalCompleted(user, animes)
|
||||||
|
|
||||||
arn.SortAnimeByQuality(animes)
|
arn.SortAnimeByQuality(animes)
|
||||||
|
|
||||||
@ -31,7 +32,7 @@ func Get(ctx *aero.Context) string {
|
|||||||
animes = animes[:animePerPage]
|
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.
|
// 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
|
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;
|
||||||
|
}
|
||||||
|
@ -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)
|
h1(title=fmt.Sprint(len(animes)) + " anime")= strings.Title(genre)
|
||||||
|
|
||||||
.average-score
|
.average-score-total-completed
|
||||||
if user != nil
|
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
|
.corner-buttons-hide-on-mobile
|
||||||
if user != nil
|
if user != nil
|
||||||
|
@ -1,2 +1,3 @@
|
|||||||
.average-score
|
.average-score-total-completed
|
||||||
text-align center
|
text-align center
|
||||||
|
font-size 1.25em
|
Loading…
Reference in New Issue
Block a user