Improved groups
This commit is contained in:
@ -2,6 +2,7 @@ package groups
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"sort"
|
||||
|
||||
"github.com/aerogo/aero"
|
||||
"github.com/animenotifier/arn"
|
||||
@ -9,6 +10,8 @@ import (
|
||||
"github.com/animenotifier/notify.moe/utils"
|
||||
)
|
||||
|
||||
const groupsPerPage = 12
|
||||
|
||||
// Get ...
|
||||
func Get(ctx *aero.Context) string {
|
||||
user := utils.GetUser(ctx)
|
||||
@ -17,9 +20,21 @@ func Get(ctx *aero.Context) string {
|
||||
return !group.IsDraft
|
||||
})
|
||||
|
||||
sort.Slice(groups, func(i, j int) bool {
|
||||
if len(groups[i].Members) == len(groups[j].Members) {
|
||||
return groups[i].Created > groups[j].Created
|
||||
}
|
||||
|
||||
return len(groups[i].Members) > len(groups[j].Members)
|
||||
})
|
||||
|
||||
if len(groups) > groupsPerPage {
|
||||
groups = groups[:groupsPerPage]
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return ctx.Error(http.StatusInternalServerError, "Error fetching groups", err)
|
||||
}
|
||||
|
||||
return ctx.HTML(components.Groups(groups, user))
|
||||
return ctx.HTML(components.Groups(groups, groupsPerPage, user))
|
||||
}
|
||||
|
Reference in New Issue
Block a user