Added posts to profile

This commit is contained in:
FM1337 2017-06-22 11:21:26 -03:00
parent ba84bd5488
commit ad7bc381ac
5 changed files with 89 additions and 15 deletions

View File

@ -61,6 +61,7 @@ func configure(app *aero.Application) *aero.Application {
app.Ajax("/user", user.Get)
app.Ajax("/user/:nick", profile.Get)
app.Ajax("/user/:nick/threads", profile.GetThreadsByUser)
app.Ajax("/user/:nick/posts", profile.GetPostsByUser)
app.Ajax("/user/:nick/animelist", animelist.Get)
app.Ajax("/user/:nick/animelist/:id", animelistitem.Get)
app.Ajax("/settings", settings.Get)

View File

@ -1,3 +1,16 @@
component PostableList(postables []arn.Postable)
each post in postables
a.ajax(href=post.Link())= post.Title()
h2.thread-title= len(postables), " latest posts by ", postables[0].Author().Nick
.thread
.posts
each post in postables
.post
.post-author
Avatar(post.Author())
.post-content
.p= post.Text()
.post-toolbar
.spacer
.post-likes= len(post.Likes())
a.post-tool.post-permalink.ajax(href="/posts/" + post.ID())
svg.icon(viewBox="0 0 1792 1792")
a.post-link.side-note.title.ajax(href="/posts/" + post.ID())= post.Title()

41
pages/profile/posts.go Normal file
View File

@ -0,0 +1,41 @@
package profile
import (
"net/http"
"github.com/aerogo/aero"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components"
)
// GetPostsbyUser shows all forum posts of a particular user.
func GetPostsByUser(ctx *aero.Context) string {
postLimit := 10
nick := ctx.Get("nick")
user, err := arn.GetUserByNick(nick)
var postables []arn.Postable
if err != nil {
return ctx.Error(http.StatusNotFound, "User not found", err)
}
posts := user.Posts()
arn.SortPostsLatestLast(posts)
if len(posts) >= postLimit {
postables = make([]arn.Postable, postLimit, postLimit)
} else {
postables = make([]arn.Postable, len(posts), len(posts))
}
for i, post := range posts {
if i == postLimit {
break
}
postables[i] = arn.ToPostable(post)
}
return ctx.HTML(components.PostableList(postables))
}

View File

@ -26,7 +26,7 @@ func Profile(ctx *aero.Context, viewUser *arn.User) string {
var user *arn.User
var threads []*arn.Thread
var animeList *arn.AnimeList
var posts []*arn.Post
aero.Parallel(func() {
user = utils.GetUser(ctx)
}, func() {
@ -39,7 +39,13 @@ func Profile(ctx *aero.Context, viewUser *arn.User) string {
if len(threads) > maxPosts {
threads = threads[:maxPosts]
}
})
},
func() {
posts = viewUser.Posts()
if len(posts) > maxPosts {
posts = posts[:maxPosts]
}
})
return ctx.HTML(components.Profile(viewUser, user, animeList, threads))
return ctx.HTML(components.Profile(viewUser, user, animeList, threads, posts))
}

View File

@ -44,7 +44,7 @@ component ProfileHeader(viewUser *arn.User, user *arn.User)
Icon("rocket")
span= arn.Capitalize(viewUser.Role)
component Profile(viewUser *arn.User, user *arn.User, animeList *arn.AnimeList, threads []*arn.Thread)
component Profile(viewUser *arn.User, user *arn.User, animeList *arn.AnimeList, threads []*arn.Thread, posts []*arn.Post)
ProfileHeader(viewUser, user)
.profile-category.mountable
@ -68,4 +68,17 @@ component Profile(viewUser *arn.User, user *arn.User, animeList *arn.AnimeList,
else
each thread in threads
ThreadLink(thread)
h3
a.ajax(href="/+" + viewUser.Nick + "/posts", title="View all Posts") Posts
if len(posts) == 0
p No posts on the forum.
else
each post in posts
.post
.post-author
Avatar(post.Author())
.post-content
.p= post.Text
.post-toolbar.active
.spacer
.post-likes= len(post.Likes)