From 97c8f994996268fddb2a782fbd286a71cf2a97e4 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Wed, 31 Oct 2018 14:27:48 +0900 Subject: [PATCH] Added activity feed --- layout/sidebar/sidebar.pixy | 4 +-- mixins/Comments.pixy | 2 +- mixins/Postable.pixy | 8 +++--- mixins/PostableList.pixy | 2 +- pages/activity/activity.go | 34 ++++++++++++++++++++++++ pages/activity/activity.pixy | 18 +++++++++++-- pages/activity/activity.scarlet | 11 ++++++++ pages/explore/explore.pixy | 3 +++ pages/explore/halloffame/halloffame.pixy | 2 +- pages/index/coreroutes/coreroutes.go | 4 +++ pages/post/post.pixy | 6 ++--- pages/post/post.scarlet | 7 +++-- pages/profile/profile.pixy | 7 ++++- pages/thread/thread.pixy | 4 +-- 14 files changed, 93 insertions(+), 19 deletions(-) create mode 100644 pages/activity/activity.go create mode 100644 pages/activity/activity.scarlet diff --git a/layout/sidebar/sidebar.pixy b/layout/sidebar/sidebar.pixy index 56c2f8d8..ad3e597c 100644 --- a/layout/sidebar/sidebar.pixy +++ b/layout/sidebar/sidebar.pixy @@ -30,10 +30,10 @@ component Sidebar(user *arn.User) SidebarButton("Home", "/+" + user.Nick + "/animelist/watching", "home") else SidebarButton("Home", "/", "home") - + + SidebarButton("Activity", "/activity", "rss") SidebarButton("Forum", "/forum", "comment") SidebarButton("Explore", "/explore", "th") - SidebarButton("Calendar", "/calendar", "calendar") SidebarButton("AMVs", "/amvs", "video-camera") SidebarButton("Soundtracks", "/soundtracks", "headphones") SidebarButton("Quotes", "/quotes", "quote-left") diff --git a/mixins/Comments.pixy b/mixins/Comments.pixy index 90933d52..5f4180bd 100644 --- a/mixins/Comments.pixy +++ b/mixins/Comments.pixy @@ -5,7 +5,7 @@ component Comments(parent arn.PostParent, user *arn.User) p.no-data.mountable No comments have been written yet. else each post in parent.Posts() - Postable(post.ToPostable(), user, "") + Postable(post.ToPostable(), user, "", "") if user != nil if parent.IsLocked() diff --git a/mixins/Postable.pixy b/mixins/Postable.pixy index 830ad2d4..e4ec4b91 100644 --- a/mixins/Postable.pixy +++ b/mixins/Postable.pixy @@ -1,12 +1,12 @@ -component Postable(post arn.Postable, user *arn.User, highlightAuthorID string) +component Postable(post arn.Postable, user *arn.User, headerContent string, highlightAuthorID string) .post.mountable(id=strings.ToLower(post.Type()) + "-" + fmt.Sprint(post.ID()), data-highlight=post.Creator().ID == highlightAuthorID, data-pro=post.Creator().IsPro(), data-api="/api/" + strings.ToLower(post.Type()) + "/" + post.ID()) .post-author Avatar(post.Creator()) - //- if post.recipient && post.recipient.ID !== post.author.ID - //- a.user.post-recipient(href="/+" + post.recipient.nick, title=post.recipient.nick) - //- img.user-image(src=post.recipient.avatar ? (post.recipient.avatar + "?s=100&r=x&d=mm") : "/images/elements/no-gravatar.svg", alt=post.recipient.nick) .post-content + if headerContent != "" + div!= headerContent + div(id="render-" + post.ID())!= post.HTML() if user != nil && user.ID == post.Creator().ID diff --git a/mixins/PostableList.pixy b/mixins/PostableList.pixy index bd31d475..6ca4f6a6 100644 --- a/mixins/PostableList.pixy +++ b/mixins/PostableList.pixy @@ -2,4 +2,4 @@ component PostableList(postables []arn.Postable, user *arn.User) .thread .posts each post in postables - Postable(post, user, "") + Postable(post, user, "", "") diff --git a/pages/activity/activity.go b/pages/activity/activity.go new file mode 100644 index 00000000..6f510e68 --- /dev/null +++ b/pages/activity/activity.go @@ -0,0 +1,34 @@ +package activity + +import ( + "github.com/aerogo/aero" + "github.com/animenotifier/arn" + "github.com/animenotifier/notify.moe/components" + "github.com/animenotifier/notify.moe/utils" +) + +const maxActivitiesPerPage = 40 + +// Get activity page. +func Get(ctx *aero.Context) string { + user := utils.GetUser(ctx) + + // posts := arn.AllPosts() + // arn.SortPostsLatestFirst(posts) + + // posts := arn.FilterPosts(func(post *arn.Post) bool { + // return post. + // }) + + entries := arn.FilterEditLogEntries(func(entry *arn.EditLogEntry) bool { + return entry.Action == "create" && entry.ObjectType == "Post" && entry.Object() != nil + }) + + arn.SortEditLogEntriesLatestFirst(entries) + + if len(entries) > maxActivitiesPerPage { + entries = entries[:maxActivitiesPerPage] + } + + return ctx.HTML(components.ActivityFeed(entries, user)) +} diff --git a/pages/activity/activity.pixy b/pages/activity/activity.pixy index 7f0dc41c..41313051 100644 --- a/pages/activity/activity.pixy +++ b/pages/activity/activity.pixy @@ -1,2 +1,16 @@ -component ActivityFeed - h1 Hello \ No newline at end of file +component ActivityFeed(entries []*arn.EditLogEntry, user *arn.User) + h1 Activity + + .activities + each entry in entries + if entry.ObjectType == "Post" + .activity + ActivityPost(entry.Object().(*arn.Post), user) + +component ActivityPost(post *arn.Post, user *arn.User) + //- .activity-header.mountable + //- a(href=post.Creator().Link())= post.Creator().Nick + //- span commented on + //- a(href=post.Parent().Link())= post.Parent().TitleByUser(user) + + Postable(post.ToPostable(), user, fmt.Sprintf(`

%s

`, post.Parent().Link(), post.Parent().TitleByUser(user)), "") \ No newline at end of file diff --git a/pages/activity/activity.scarlet b/pages/activity/activity.scarlet new file mode 100644 index 00000000..cedd67fc --- /dev/null +++ b/pages/activity/activity.scarlet @@ -0,0 +1,11 @@ +.activities + vertical + width 100% + max-width forum-width + margin 0 auto + +// .activity +// margin-bottom 1rem + +.activity-header + font-size 0.9rem \ No newline at end of file diff --git a/pages/explore/explore.pixy b/pages/explore/explore.pixy index 29d48e42..f5c3faad 100644 --- a/pages/explore/explore.pixy +++ b/pages/explore/explore.pixy @@ -7,6 +7,9 @@ component ExploreAnime(animes []*arn.Anime, year string, season string, status s button.action(data-trigger="click", data-action="toggleHideAddedAnime", title="Hide anime in my collection") RawIcon("eye-slash") + a.button(href="/calendar", title="Calendar") + RawIcon("calendar") + a.button(href="/halloffame", title="Hall of Fame") RawIcon("trophy") diff --git a/pages/explore/halloffame/halloffame.pixy b/pages/explore/halloffame/halloffame.pixy index 842b130e..e9f456ee 100644 --- a/pages/explore/halloffame/halloffame.pixy +++ b/pages/explore/halloffame/halloffame.pixy @@ -1,6 +1,6 @@ component HallOfFame(entries []*utils.HallOfFameEntry, user *arn.User) h1.hall-of-fame-page-title Hall of Fame - .footer Best TV series for each year. + .footer Most popular TV series for each year. .hall-of-fame each entry in entries diff --git a/pages/index/coreroutes/coreroutes.go b/pages/index/coreroutes/coreroutes.go index 1a7ae234..60276157 100644 --- a/pages/index/coreroutes/coreroutes.go +++ b/pages/index/coreroutes/coreroutes.go @@ -2,6 +2,7 @@ package coreroutes import ( "github.com/aerogo/layout" + "github.com/animenotifier/notify.moe/pages/activity" "github.com/animenotifier/notify.moe/pages/calendar" "github.com/animenotifier/notify.moe/pages/embed" "github.com/animenotifier/notify.moe/pages/home" @@ -18,6 +19,9 @@ func Register(l *layout.Layout) { // Login l.Page("/login", login.Get) + // Activity + l.Page("/activity", activity.Get) + // Calendar l.Page("/calendar", calendar.Get) diff --git a/pages/post/post.pixy b/pages/post/post.pixy index 90d193f0..8b9fb987 100644 --- a/pages/post/post.pixy +++ b/pages/post/post.pixy @@ -1,7 +1,7 @@ component Post(post *arn.Post, user *arn.User) .thread .posts - Postable(post.ToPostable(), user, "") + Postable(post.ToPostable(), user, "", "") - .side-note.mountable - a(href=post.Parent().Link())= post.Parent().TitleByUser(user) + .side-note-container.mountable + a.side-note(href=post.Parent().Link())= post.Parent().TitleByUser(user) diff --git a/pages/post/post.scarlet b/pages/post/post.scarlet index 14b7721e..940d41ff 100644 --- a/pages/post/post.scarlet +++ b/pages/post/post.scarlet @@ -1,3 +1,6 @@ +.side-note-container + horizontal + justify-content flex-end + .side-note - font-size 0.9rem - text-align right !important \ No newline at end of file + font-size 0.9rem \ No newline at end of file diff --git a/pages/profile/profile.pixy b/pages/profile/profile.pixy index 4059da67..b1ac70db 100644 --- a/pages/profile/profile.pixy +++ b/pages/profile/profile.pixy @@ -79,7 +79,7 @@ component ProfileHead(viewUser *arn.User, user *arn.User, uri string) //- span= viewUser.Accounts.FinalFantasyXIV.Class if viewUser.Registered != "" - .profile-tag.tip.mountable.never-unmount(aria-label="Member since", data-mountable-type="header") + .profile-tag.mountable.never-unmount(title="Member since", data-mountable-type="header") Icon("calendar") span= viewUser.RegisteredTime().Format("Jan 2006") @@ -92,6 +92,11 @@ component ProfileHead(viewUser *arn.User, user *arn.User, uri string) a.profile-tag.mountable.never-unmount(href="/users/staff", aria-label="Staff member", data-mountable-type="header") Icon("rocket") span= stringutils.Capitalize(viewUser.Role) + + if !viewUser.IsActive() + .profile-tag.mountable.never-unmount(title="Hasn't been online for the past 2 weeks", data-mountable-type="header") + Icon("bed") + span Inactive //- if user != nil && user.ID != viewUser.ID //- a.button.profile-action(href="/compare/animelist/" + user.Nick + "/" + viewUser.Nick) diff --git a/pages/thread/thread.pixy b/pages/thread/thread.pixy index 4ba37795..7e55f2f2 100644 --- a/pages/thread/thread.pixy +++ b/pages/thread/thread.pixy @@ -3,10 +3,10 @@ component Thread(thread *arn.Thread, posts []*arn.Post, user *arn.User) #thread.thread(data-id=thread.ID) .posts - Postable(thread.ToPostable(), user, thread.Creator().ID) + Postable(thread.ToPostable(), user, "", thread.Creator().ID) each post in posts - Postable(post.ToPostable(), user, thread.Creator().ID) + Postable(post.ToPostable(), user, "", thread.Creator().ID) //- Reply if user != nil