From c0e324cefd55ff29a9c1678dfd0d84967e282025 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Fri, 21 Jul 2017 11:01:34 +0200 Subject: [PATCH] Followers --- main.go | 1 + pages/profile/followers.go | 30 ++++++++++++++++++++++++++++++ pages/profile/followers.pixy | 11 +++++++++++ pages/profile/profile.pixy | 4 ++++ 4 files changed, 46 insertions(+) create mode 100644 pages/profile/followers.go create mode 100644 pages/profile/followers.pixy diff --git a/main.go b/main.go index d1cdc12a..534ed8b5 100644 --- a/main.go +++ b/main.go @@ -97,6 +97,7 @@ func configure(app *aero.Application) *aero.Application { app.Ajax("/user/:nick/posts", profile.GetPostsByUser) app.Ajax("/user/:nick/soundtracks", profile.GetSoundTracksByUser) app.Ajax("/user/:nick/stats", profile.GetStatsByUser) + app.Ajax("/user/:nick/followers", profile.GetFollowers) app.Ajax("/user/:nick/animelist", animelist.Get) app.Ajax("/user/:nick/animelist/watching", animelist.FilterByStatus(arn.AnimeListStatusWatching)) app.Ajax("/user/:nick/animelist/completed", animelist.FilterByStatus(arn.AnimeListStatusCompleted)) diff --git a/pages/profile/followers.go b/pages/profile/followers.go new file mode 100644 index 00000000..ef14813f --- /dev/null +++ b/pages/profile/followers.go @@ -0,0 +1,30 @@ +package profile + +import ( + "net/http" + "sort" + + "github.com/aerogo/aero" + "github.com/animenotifier/arn" + "github.com/animenotifier/notify.moe/components" + "github.com/animenotifier/notify.moe/utils" +) + +// GetFollowers shows the followers of a particular user. +func GetFollowers(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) + } + + followers := viewUser.Followers() + + sort.Slice(followers, func(i, j int) bool { + return followers[i].LastSeen > followers[j].LastSeen + }) + + return ctx.HTML(components.ProfileFollowers(followers, viewUser, utils.GetUser(ctx), ctx.URI())) + +} diff --git a/pages/profile/followers.pixy b/pages/profile/followers.pixy new file mode 100644 index 00000000..50e25b72 --- /dev/null +++ b/pages/profile/followers.pixy @@ -0,0 +1,11 @@ +component ProfileFollowers(followers []*arn.User, viewUser *arn.User, user *arn.User, uri string) + ProfileHeader(viewUser, user, uri) + + if len(followers) > 0 + .user-avatars + each user in followers + if user.Nick != "" + .mountable + Avatar(user) + else + p.no-data.mountable= viewUser.Nick + " doesn't have a follower yet." \ No newline at end of file diff --git a/pages/profile/profile.pixy b/pages/profile/profile.pixy index 0b3cca2c..85aff0e2 100644 --- a/pages/profile/profile.pixy +++ b/pages/profile/profile.pixy @@ -88,6 +88,10 @@ component ProfileNavigation(viewUser *arn.User, uri string) a.button.tab.action(href="/+" + viewUser.Nick + "/stats", data-action="diff", data-trigger="click") Icon("area-chart") span.tab-text Stats + + a.button.tab.action(href="/+" + viewUser.Nick + "/followers", data-action="diff", data-trigger="click") + Icon("users") + span.tab-text Followers if strings.Contains(uri, "/animelist") hr