From ad7bc381ac0d7b16f44c34fabe11d4d222ff68d2 Mon Sep 17 00:00:00 2001 From: FM1337 Date: Thu, 22 Jun 2017 11:21:26 -0300 Subject: [PATCH 1/3] Added posts to profile --- main.go | 1 + mixins/PostableList.pixy | 17 ++++++++++++++-- pages/profile/posts.go | 41 ++++++++++++++++++++++++++++++++++++++ pages/profile/profile.go | 12 ++++++++--- pages/profile/profile.pixy | 33 ++++++++++++++++++++---------- 5 files changed, 89 insertions(+), 15 deletions(-) create mode 100644 pages/profile/posts.go diff --git a/main.go b/main.go index 60dd7a12..4e277623 100644 --- a/main.go +++ b/main.go @@ -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) diff --git a/mixins/PostableList.pixy b/mixins/PostableList.pixy index d7f6af2e..73dbe0b2 100644 --- a/mixins/PostableList.pixy +++ b/mixins/PostableList.pixy @@ -1,3 +1,16 @@ component PostableList(postables []arn.Postable) - each post in postables - a.ajax(href=post.Link())= post.Title() \ No newline at end of file + 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() diff --git a/pages/profile/posts.go b/pages/profile/posts.go new file mode 100644 index 00000000..4bb9d913 --- /dev/null +++ b/pages/profile/posts.go @@ -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)) + +} diff --git a/pages/profile/profile.go b/pages/profile/profile.go index 8cfbeba9..9a8f76fc 100644 --- a/pages/profile/profile.go +++ b/pages/profile/profile.go @@ -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)) } diff --git a/pages/profile/profile.pixy b/pages/profile/profile.pixy index 352cbf32..3d044dc9 100644 --- a/pages/profile/profile.pixy +++ b/pages/profile/profile.pixy @@ -4,7 +4,7 @@ component ProfileHeader(viewUser *arn.User, user *arn.User) .image-container.mountable ProfileImage(viewUser) - + .intro-container.mountable h2#nick= viewUser.Nick @@ -16,37 +16,37 @@ component ProfileHeader(viewUser *arn.User, user *arn.User) p.profile-field.tagline Icon("comment") span.tagline-text No tagline yet. - + if viewUser.Website != "" p.profile-field.website Icon("home") a(href=viewUser.WebsiteURL(), target="_blank", rel="nofollow")= viewUser.Website - + if viewUser.Accounts.Osu.Nick != "" && viewUser.Accounts.Osu.PP >= 1000 p.profile-field.osu(title="osu! performance points") Icon("trophy") span= toString(int(viewUser.Accounts.Osu.PP)) + " pp" - + //- if viewUser.dataEditCount //- p.profile-field.editor-contribution(title="Anime data modifications") //- Icon("edit") //- span= viewUser.dataEditCount - + if viewUser.Registered != "" p.profile-field.registration-date(title="Member since") Icon("calendar") //- span= time.Parse(time.RFC3339, viewUser.Registered) span= viewUser.RegisteredTime().Format("Jan 2006") //- span= monthNames[joined.getMonth()] + ' ' + joined.getFullYear() - + if viewUser.Role != "" p.profile-field.role 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 h3 a.ajax(href="/+" + viewUser.Nick + "/animelist", title="View all anime") Anime @@ -62,10 +62,23 @@ component Profile(viewUser *arn.User, user *arn.User, animeList *arn.AnimeList, .profile-category.mountable h3 a.ajax(href="/+" + viewUser.Nick + "/threads", title="View all threads") Threads - + if len(threads) == 0 p No threads on the forum. else each thread in threads ThreadLink(thread) - \ No newline at end of file + 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) From f6e5b6da08d50515b396265e03fb488c0b66736f Mon Sep 17 00:00:00 2001 From: FM1337 Date: Thu, 22 Jun 2017 12:03:43 -0300 Subject: [PATCH 2/3] Fixed mistakes --- mixins/PostableList.pixy | 6 +++--- pages/profile/posts.go | 17 ++++++++--------- pages/profile/profile.go | 16 +++++++++------- pages/profile/profile.pixy | 4 ++-- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/mixins/PostableList.pixy b/mixins/PostableList.pixy index 73dbe0b2..fd050961 100644 --- a/mixins/PostableList.pixy +++ b/mixins/PostableList.pixy @@ -7,10 +7,10 @@ component PostableList(postables []arn.Postable) .post-author Avatar(post.Author()) .post-content - .p= post.Text() + p!= aero.Markdown(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-tool.post-permalink.ajax(href=post.Link(), title="Permalink") + Icon("link") a.post-link.side-note.title.ajax(href="/posts/" + post.ID())= post.Title() diff --git a/pages/profile/posts.go b/pages/profile/posts.go index 4bb9d913..cb4cad06 100644 --- a/pages/profile/posts.go +++ b/pages/profile/posts.go @@ -8,32 +8,31 @@ import ( "github.com/animenotifier/notify.moe/components" ) +const postLimit = 10 + // 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) + var postables []arn.Postable if len(posts) >= postLimit { - postables = make([]arn.Postable, postLimit, postLimit) - } else { - postables = make([]arn.Postable, len(posts), len(posts)) + posts = posts[:postLimit] } + 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)) diff --git a/pages/profile/profile.go b/pages/profile/profile.go index 9a8f76fc..15ffeecb 100644 --- a/pages/profile/profile.go +++ b/pages/profile/profile.go @@ -27,6 +27,7 @@ func Profile(ctx *aero.Context, viewUser *arn.User) string { var threads []*arn.Thread var animeList *arn.AnimeList var posts []*arn.Post + aero.Parallel(func() { user = utils.GetUser(ctx) }, func() { @@ -39,13 +40,14 @@ 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] - } - }) + }, func() { + posts = viewUser.Posts() + + if len(posts) > maxPosts { + posts = posts[:maxPosts] + } + + }) return ctx.HTML(components.Profile(viewUser, user, animeList, threads, posts)) } diff --git a/pages/profile/profile.pixy b/pages/profile/profile.pixy index 3d044dc9..5e5369ba 100644 --- a/pages/profile/profile.pixy +++ b/pages/profile/profile.pixy @@ -69,7 +69,7 @@ component Profile(viewUser *arn.User, user *arn.User, animeList *arn.AnimeList, each thread in threads ThreadLink(thread) h3 - a.ajax(href="/+" + viewUser.Nick + "/posts", title="View all Posts") Posts + a.ajax(href="/+" + viewUser.Nick + "/posts", title="View all posts") Posts if len(posts) == 0 p No posts on the forum. else @@ -78,7 +78,7 @@ component Profile(viewUser *arn.User, user *arn.User, animeList *arn.AnimeList, .post-author Avatar(post.Author()) .post-content - .p= post.Text + p!= aero.Markdown(post.Text) .post-toolbar.active .spacer .post-likes= len(post.Likes) From 7743a0192580e7e44fac9c7972ab3b20ef2f9689 Mon Sep 17 00:00:00 2001 From: FM1337 Date: Thu, 22 Jun 2017 12:13:55 -0300 Subject: [PATCH 3/3] Final changes (hopefully) for adding posts to profile --- mixins/PostableList.pixy | 2 +- pages/profile/posts.go | 1 + pages/profile/profile.go | 1 - 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mixins/PostableList.pixy b/mixins/PostableList.pixy index fd050961..ce6f4c10 100644 --- a/mixins/PostableList.pixy +++ b/mixins/PostableList.pixy @@ -13,4 +13,4 @@ component PostableList(postables []arn.Postable) .post-likes= len(post.Likes()) a.post-tool.post-permalink.ajax(href=post.Link(), title="Permalink") Icon("link") - a.post-link.side-note.title.ajax(href="/posts/" + post.ID())= post.Title() + a.post-link.side-note.ajax(href=post.Link())= post.Title() diff --git a/pages/profile/posts.go b/pages/profile/posts.go index cb4cad06..ea60c93e 100644 --- a/pages/profile/posts.go +++ b/pages/profile/posts.go @@ -21,6 +21,7 @@ func GetPostsByUser(ctx *aero.Context) string { posts := user.Posts() arn.SortPostsLatestLast(posts) + var postables []arn.Postable if len(posts) >= postLimit { diff --git a/pages/profile/profile.go b/pages/profile/profile.go index 15ffeecb..185d41a7 100644 --- a/pages/profile/profile.go +++ b/pages/profile/profile.go @@ -46,7 +46,6 @@ func Profile(ctx *aero.Context, viewUser *arn.User) string { if len(posts) > maxPosts { posts = posts[:maxPosts] } - }) return ctx.HTML(components.Profile(viewUser, user, animeList, threads, posts))