Sort character anime by date

This commit is contained in:
Eduard Urbach 2017-11-20 09:01:28 +01:00
parent 5bab3cf753
commit 1f445feee4
2 changed files with 18 additions and 3 deletions

View File

@ -2,6 +2,7 @@ package character
import (
"net/http"
"sort"
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
@ -19,5 +20,19 @@ func Get(ctx *aero.Context) string {
return ctx.Error(http.StatusNotFound, "Character not found", err)
}
return ctx.HTML(components.CharacterDetails(character, user))
characterAnime := character.Anime()
sort.Slice(characterAnime, func(i, j int) bool {
if characterAnime[i].StartDate == "" {
return false
}
if characterAnime[j].StartDate == "" {
return true
}
return characterAnime[i].StartDate < characterAnime[j].StartDate
})
return ctx.HTML(components.CharacterDetails(character, characterAnime, user))
}

View File

@ -1,4 +1,4 @@
component CharacterDetails(character *arn.Character, user *arn.User)
component CharacterDetails(character *arn.Character, characterAnime []*arn.Anime, user *arn.User)
.character-page
.character-left-column
.character-header
@ -12,7 +12,7 @@ component CharacterDetails(character *arn.Character, user *arn.User)
h3 Anime
.character-anime
each anime in character.Anime()
each anime in characterAnime
a.character-anime-item.ajax(href=anime.Link(), title=anime.Title.ByUser(user))
img.character-anime-item-image.lazy(data-src=anime.Image("small"), data-webp="true", alt=anime.Title.ByUser(user))