Added joined groups page
This commit is contained in:
@ -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
|
||||
})
|
||||
}
|
||||
|
@ -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
|
||||
|
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.
|
||||
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
|
||||
|
@ -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) {
|
||||
|
@ -9,8 +9,8 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
groupsFirstLoad = 24
|
||||
groupsPerScroll = 12
|
||||
groupsFirstLoad = 27
|
||||
groupsPerScroll = 18
|
||||
)
|
||||
|
||||
// render renders the groups page with the given groups.
|
||||
|
Reference in New Issue
Block a user