Added joined groups page
This commit is contained in:
parent
da08f80247
commit
7243d02e85
@ -2,8 +2,16 @@ package groups
|
|||||||
|
|
||||||
import "github.com/animenotifier/arn"
|
import "github.com/animenotifier/arn"
|
||||||
|
|
||||||
func fetchGroups() []*arn.Group {
|
func fetchGroups(memberID string) []*arn.Group {
|
||||||
return arn.FilterGroups(func(group *arn.Group) bool {
|
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
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,9 @@ component Groups(groups []*arn.Group, nextIndex int, user *arn.User)
|
|||||||
Tab("Latest", "users", "/groups")
|
Tab("Latest", "users", "/groups")
|
||||||
Tab("Popular", "globe", "/groups/popular")
|
Tab("Popular", "globe", "/groups/popular")
|
||||||
|
|
||||||
|
if user != nil
|
||||||
|
Tab("Joined", "user-plus", "/groups/joined")
|
||||||
|
|
||||||
h1.page-title Groups
|
h1.page-title Groups
|
||||||
|
|
||||||
.corner-buttons
|
.corner-buttons
|
||||||
|
31
pages/groups/joined.go
Normal file
31
pages/groups/joined.go
Normal file
@ -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)
|
||||||
|
}
|
@ -8,7 +8,7 @@ import (
|
|||||||
|
|
||||||
// Latest shows the latest groups.
|
// Latest shows the latest groups.
|
||||||
func Latest(ctx *aero.Context) string {
|
func Latest(ctx *aero.Context) string {
|
||||||
groups := fetchGroups()
|
groups := fetchGroups("")
|
||||||
|
|
||||||
sort.Slice(groups, func(i, j int) bool {
|
sort.Slice(groups, func(i, j int) bool {
|
||||||
return groups[i].Created > groups[j].Created
|
return groups[i].Created > groups[j].Created
|
||||||
|
@ -8,7 +8,7 @@ import (
|
|||||||
|
|
||||||
// Popular shows the most popular groups.
|
// Popular shows the most popular groups.
|
||||||
func Popular(ctx *aero.Context) string {
|
func Popular(ctx *aero.Context) string {
|
||||||
groups := fetchGroups()
|
groups := fetchGroups("")
|
||||||
|
|
||||||
sort.Slice(groups, func(i, j int) bool {
|
sort.Slice(groups, func(i, j int) bool {
|
||||||
if len(groups[i].Members) == len(groups[j].Members) {
|
if len(groups[i].Members) == len(groups[j].Members) {
|
||||||
|
@ -9,8 +9,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
groupsFirstLoad = 24
|
groupsFirstLoad = 27
|
||||||
groupsPerScroll = 12
|
groupsPerScroll = 18
|
||||||
)
|
)
|
||||||
|
|
||||||
// render renders the groups page with the given groups.
|
// render renders the groups page with the given groups.
|
||||||
|
@ -13,6 +13,8 @@ func Register(l *layout.Layout) {
|
|||||||
l.Page("/groups/from/:index", groups.Latest)
|
l.Page("/groups/from/:index", groups.Latest)
|
||||||
l.Page("/groups/popular", groups.Popular)
|
l.Page("/groups/popular", groups.Popular)
|
||||||
l.Page("/groups/popular/from/:index", 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", group.Feed)
|
||||||
l.Page("/group/:id/info", group.Info)
|
l.Page("/group/:id/info", group.Info)
|
||||||
l.Page("/group/:id/members", group.Members)
|
l.Page("/group/:id/members", group.Members)
|
||||||
|
@ -467,6 +467,7 @@ var routeTests = map[string][]string{
|
|||||||
"/editor/anilist": nil,
|
"/editor/anilist": nil,
|
||||||
"/editor/shoboi": nil,
|
"/editor/shoboi": nil,
|
||||||
"/dark-flame-master": nil,
|
"/dark-flame-master": nil,
|
||||||
|
"/groups/joined": nil,
|
||||||
"/user": nil,
|
"/user": nil,
|
||||||
"/settings": nil,
|
"/settings": nil,
|
||||||
"/settings/accounts": nil,
|
"/settings/accounts": nil,
|
||||||
|
Loading…
Reference in New Issue
Block a user