From 7243d02e85a43449c75a6f266f362ef68e2740b0 Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Thu, 22 Nov 2018 11:51:44 +0900 Subject: [PATCH] Added joined groups page --- pages/groups/fetch.go | 12 ++++++++-- pages/groups/groups.pixy | 3 +++ pages/groups/joined.go | 31 ++++++++++++++++++++++++++ pages/groups/latest.go | 2 +- pages/groups/popular.go | 2 +- pages/groups/render.go | 4 ++-- pages/index/grouproutes/grouproutes.go | 2 ++ utils/routetests/All.go | 1 + 8 files changed, 51 insertions(+), 6 deletions(-) create mode 100644 pages/groups/joined.go diff --git a/pages/groups/fetch.go b/pages/groups/fetch.go index 7dab0e3c..5d20c5b9 100644 --- a/pages/groups/fetch.go +++ b/pages/groups/fetch.go @@ -2,8 +2,16 @@ package groups import "github.com/animenotifier/arn" -func fetchGroups() []*arn.Group { +func fetchGroups(memberID string) []*arn.Group { return arn.FilterGroups(func(group *arn.Group) bool { - return !group.IsDraft + if group.IsDraft { + return false + } + + if memberID != "" && !group.HasMember(memberID) { + return false + } + + return true }) } diff --git a/pages/groups/groups.pixy b/pages/groups/groups.pixy index 1f89c509..bd5b6e2c 100644 --- a/pages/groups/groups.pixy +++ b/pages/groups/groups.pixy @@ -3,6 +3,9 @@ component Groups(groups []*arn.Group, nextIndex int, user *arn.User) Tab("Latest", "users", "/groups") Tab("Popular", "globe", "/groups/popular") + if user != nil + Tab("Joined", "user-plus", "/groups/joined") + h1.page-title Groups .corner-buttons diff --git a/pages/groups/joined.go b/pages/groups/joined.go new file mode 100644 index 00000000..5de003c1 --- /dev/null +++ b/pages/groups/joined.go @@ -0,0 +1,31 @@ +package groups + +import ( + "net/http" + "sort" + + "github.com/animenotifier/notify.moe/utils" + + "github.com/aerogo/aero" +) + +// Joined shows the most popular joined groups. +func Joined(ctx *aero.Context) string { + user := utils.GetUser(ctx) + + if user == nil { + return ctx.Error(http.StatusUnauthorized, "Not logged in") + } + + groups := fetchGroups(user.ID) + + // Sort by join date + sort.Slice(groups, func(i, j int) bool { + aMember := groups[i].FindMember(user.ID) + bMember := groups[j].FindMember(user.ID) + + return aMember.Joined > bMember.Joined + }) + + return render(ctx, groups) +} diff --git a/pages/groups/latest.go b/pages/groups/latest.go index ac9e24d4..1fbf074f 100644 --- a/pages/groups/latest.go +++ b/pages/groups/latest.go @@ -8,7 +8,7 @@ import ( // Latest shows the latest groups. func Latest(ctx *aero.Context) string { - groups := fetchGroups() + groups := fetchGroups("") sort.Slice(groups, func(i, j int) bool { return groups[i].Created > groups[j].Created diff --git a/pages/groups/popular.go b/pages/groups/popular.go index 1547cf54..bfc52941 100644 --- a/pages/groups/popular.go +++ b/pages/groups/popular.go @@ -8,7 +8,7 @@ import ( // Popular shows the most popular groups. func Popular(ctx *aero.Context) string { - groups := fetchGroups() + groups := fetchGroups("") sort.Slice(groups, func(i, j int) bool { if len(groups[i].Members) == len(groups[j].Members) { diff --git a/pages/groups/render.go b/pages/groups/render.go index c9b3f619..4bf29c7d 100644 --- a/pages/groups/render.go +++ b/pages/groups/render.go @@ -9,8 +9,8 @@ import ( ) const ( - groupsFirstLoad = 24 - groupsPerScroll = 12 + groupsFirstLoad = 27 + groupsPerScroll = 18 ) // render renders the groups page with the given groups. diff --git a/pages/index/grouproutes/grouproutes.go b/pages/index/grouproutes/grouproutes.go index 2975bf11..1ee268e4 100644 --- a/pages/index/grouproutes/grouproutes.go +++ b/pages/index/grouproutes/grouproutes.go @@ -13,6 +13,8 @@ func Register(l *layout.Layout) { l.Page("/groups/from/:index", groups.Latest) l.Page("/groups/popular", groups.Popular) l.Page("/groups/popular/from/:index", groups.Popular) + l.Page("/groups/joined", groups.Joined) + l.Page("/groups/joined/from/:index", groups.Joined) l.Page("/group/:id", group.Feed) l.Page("/group/:id/info", group.Info) l.Page("/group/:id/members", group.Members) diff --git a/utils/routetests/All.go b/utils/routetests/All.go index 2476daed..114da85f 100644 --- a/utils/routetests/All.go +++ b/utils/routetests/All.go @@ -467,6 +467,7 @@ var routeTests = map[string][]string{ "/editor/anilist": nil, "/editor/shoboi": nil, "/dark-flame-master": nil, + "/groups/joined": nil, "/user": nil, "/settings": nil, "/settings/accounts": nil,