Added sorting options for anime lists

This commit is contained in:
2019-08-29 12:23:58 +09:00
parent cdfb66657a
commit e28618029a
14 changed files with 153 additions and 134 deletions

View File

@ -22,11 +22,17 @@ const (
func Filter(ctx aero.Context) error {
user := utils.GetUser(ctx)
status := ctx.Get("status")
return AnimeList(ctx, user, status)
sortBy := arn.SortByRating
if user != nil {
sortBy = user.Settings().SortBy
}
return AnimeList(ctx, user, status, sortBy)
}
// AnimeList renders the anime list items.
func AnimeList(ctx aero.Context, user *arn.User, status string) error {
func AnimeList(ctx aero.Context, user *arn.User, status string, sortBy string) error {
nick := ctx.Get("nick")
index, _ := ctx.GetInt("index")
viewUser, err := arn.GetUserByNick(nick)
@ -50,9 +56,9 @@ func AnimeList(ctx aero.Context, user *arn.User, status string) error {
}
// Sort the items
statusList.Sort()
statusList.Sort(sortBy)
// These are all animer list items for the given status
// These are all anime list items for the given status
allItems := statusList.Items
// Slice the part that we need

View File

@ -33,7 +33,7 @@ func Get(ctx aero.Context) error {
}
watchingList := animeList.Watching()
watchingList.Sort()
watchingList.Sort(user.Settings().SortBy)
return ctx.HTML(components.BrowserExtension(watchingList, animeList.User(), user))
}

View File

@ -34,6 +34,11 @@ func Get(ctx aero.Context) error {
// Profile renders the user profile page of the given viewUser.
func Profile(ctx aero.Context, viewUser *arn.User) error {
user := utils.GetUser(ctx)
sortBy := arn.SortByRating
if user != nil {
sortBy = user.Settings().SortBy
}
// Anime list
animeList := viewUser.AnimeList()
@ -43,7 +48,7 @@ func Profile(ctx aero.Context, viewUser *arn.User) error {
}
completedList := animeList.FilterStatus(arn.AnimeListStatusCompleted)
completedList.SortByRating()
completedList.Sort(sortBy)
// Genres
topGenres := animeList.TopGenres(5)

View File

@ -7,7 +7,7 @@ component SettingsStyle(user *arn.User)
.widget.mountable(data-api="/api/settings/" + user.ID)
h3.widget-title
Icon("font")
span Style
span General
.widget-section
label(for="Theme")= "Theme:"
@ -24,7 +24,19 @@ component SettingsStyle(user *arn.User)
option(value="japanese") 日本語
InputNumber("Format.RatingsPrecision", float64(user.Settings().Format.RatingsPrecision), "Ratings precision", "How many decimals after the comma would you like to display in ratings on anime pages?", "0", "2", "1")
.widget.mountable(data-api="/api/settings/" + user.ID)
h3.widget-title
Icon("list")
span List
.widget-section
label(for="SortBy")= "Sort by:"
select.widget-ui-element.action(id="SortBy", data-field="SortBy", value=user.Settings().SortBy, title="Sorting algorithm for anime lists", data-action="save", data-trigger="change")
option(value="airing date") Airing date ⮞ Rating ⮞ Title
option(value="rating") Rating ⮞ Title
option(value="title") Title
if arn.IsDevelopment()
.widget.mountable(data-api="/api/settings/" + user.ID)
h3.widget-title