Liked characters are now viewable

This commit is contained in:
Eduard Urbach 2019-03-11 09:37:05 +09:00
parent 452a340fff
commit a37d636d67
6 changed files with 55 additions and 47 deletions

View File

@ -9,6 +9,7 @@ import (
"github.com/animenotifier/notify.moe/pages/explore/explorerelations"
"github.com/animenotifier/notify.moe/pages/notifications"
"github.com/animenotifier/notify.moe/pages/profile"
"github.com/animenotifier/notify.moe/pages/profile/profilecharacters"
"github.com/animenotifier/notify.moe/pages/recommended"
"github.com/animenotifier/notify.moe/pages/user"
)
@ -18,7 +19,7 @@ func Register(l *layout.Layout) {
// User profiles
l.Page("/user", user.Get)
l.Page("/user/:nick", profile.Get)
// l.Page("/user/:nick/characters/liked", profilecharacters.Liked)
l.Page("/user/:nick/characters/liked", profilecharacters.Liked)
// l.Page("/user/:nick/forum/threads", profile.GetThreadsByUser)
// l.Page("/user/:nick/forum/posts", profile.GetPostsByUser)
// l.Page("/user/:nick/soundtracks/added", profiletracks.Added)

View File

@ -19,7 +19,8 @@ component Profile(viewUser *arn.User, user *arn.User, animeList *arn.AnimeList,
//- Characters
.profile-section
h3.profile-column-header.mountable(data-mountable-type="favorites") Characters
h3.profile-column-header.mountable(data-mountable-type="favorites")
a(href=viewUser.Link() + "/characters/liked") Characters
if len(characters) == 0
p.no-data.mountable(data-mountable-type="favorites") Nothing here yet.
@ -101,10 +102,13 @@ component ProfileHead(viewUser *arn.User, animeList *arn.AnimeList, user *arn.Us
img.profile-cover.lazy(data-src=viewUser.CoverLink("large"), data-webp="true", alt="Cover image")
.profile-image-container.mountable.never-unmount
a(href=viewUser.Link())
ProfileImage(viewUser)
.profile-info.mountable.never-unmount
h1#nick= viewUser.Nick
h1#nick
a(href=viewUser.Link())= viewUser.Nick
.profile-introduction!= markdown.Render(viewUser.Introduction)
.profile-tags-container

View File

@ -227,6 +227,9 @@ const box-margin = 2px
#nick
margin-bottom 1rem
> a
color white
.no-data
width 100%
text-align center

View File

@ -1,10 +1,10 @@
//- component ProfileCharacters(characters []*arn.Character, viewUser *arn.User, user *arn.User, uri string)
//- ProfileHeader(viewUser, user, uri)
component ProfileCharacters(characters []*arn.Character, viewUser *arn.User, user *arn.User, uri string)
ProfileHeader(viewUser, viewUser.AnimeList(), user, uri)
//- if len(characters) == 0
//- p.no-data.mountable= viewUser.Nick + " hasn't liked any characters yet."
//- else
//- .characters.profile-characters
//- each character in characters
//- .mountable
//- Character(character, user)
if len(characters) == 0
p.no-data.mountable= viewUser.Nick + " hasn't liked any characters yet."
else
.characters.profile-characters
each character in characters
.mountable
Character(character, user)

View File

@ -1,2 +1,2 @@
// .profile-characters
// justify-content center
.profile-characters
justify-content center

View File

@ -1,44 +1,44 @@
package profilecharacters
// import (
// "net/http"
// "sort"
import (
"net/http"
"sort"
// "github.com/aerogo/aero"
// "github.com/animenotifier/arn"
// "github.com/animenotifier/notify.moe/components"
// "github.com/animenotifier/notify.moe/utils"
// )
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components"
"github.com/animenotifier/notify.moe/utils"
)
// // Liked shows all liked characters of a particular user.
// func Liked(ctx *aero.Context) string {
// nick := ctx.Get("nick")
// viewUser, err := arn.GetUserByNick(nick)
// Liked shows all liked characters of a particular user.
func Liked(ctx *aero.Context) string {
nick := ctx.Get("nick")
viewUser, err := arn.GetUserByNick(nick)
// if err != nil {
// return ctx.Error(http.StatusNotFound, "User not found", err)
// }
if err != nil {
return ctx.Error(http.StatusNotFound, "User not found", err)
}
// characters := []*arn.Character{}
characters := []*arn.Character{}
// for character := range arn.StreamCharacters() {
// if arn.Contains(character.Likes, viewUser.ID) {
// characters = append(characters, character)
// }
// }
for character := range arn.StreamCharacters() {
if arn.Contains(character.Likes, viewUser.ID) {
characters = append(characters, character)
}
}
// sort.Slice(characters, func(i, j int) bool {
sort.Slice(characters, func(i, j int) bool {
return characters[i].Name.Canonical < characters[j].Name.Canonical
// aLikes := len(characters[i].Likes)
// bLikes := len(characters[j].Likes)
// if aLikes == bLikes {
// return characters[i].Name.Canonical < characters[j].Name.Canonical
// // aLikes := len(characters[i].Likes)
// // bLikes := len(characters[j].Likes)
// // if aLikes == bLikes {
// // return characters[i].Name.Canonical < characters[j].Name.Canonical
// // }
// // return aLikes > bLikes
// })
// return ctx.HTML(components.ProfileCharacters(characters, viewUser, utils.GetUser(ctx), ctx.URI()))
// }
// return aLikes > bLikes
})
return ctx.HTML(components.ProfileCharacters(characters, viewUser, utils.GetUser(ctx), ctx.URI()))
}