Improved company list
This commit is contained in:
pages/companies
@ -2,6 +2,7 @@ package companies
|
||||
|
||||
import (
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/aerogo/aero"
|
||||
"github.com/animenotifier/arn"
|
||||
@ -9,8 +10,6 @@ import (
|
||||
"github.com/animenotifier/notify.moe/utils"
|
||||
)
|
||||
|
||||
const maxEntries = 24
|
||||
|
||||
// Get renders the companies page.
|
||||
func Get(ctx *aero.Context) string {
|
||||
user := utils.GetUser(ctx)
|
||||
@ -20,12 +19,25 @@ func Get(ctx *aero.Context) string {
|
||||
})
|
||||
|
||||
sort.Slice(companies, func(i, j int) bool {
|
||||
return companies[i].Created > companies[j].Created
|
||||
return strings.ToLower(companies[i].Name.English) < strings.ToLower(companies[j].Name.English)
|
||||
})
|
||||
|
||||
if len(companies) > maxEntries {
|
||||
companies = companies[:maxEntries]
|
||||
groups := [][]*arn.Company{}
|
||||
currentGroupIndex := -1
|
||||
|
||||
previousFirstLetter := ""
|
||||
|
||||
for _, company := range companies {
|
||||
firstLetter := strings.ToLower(company.Name.English[:1])
|
||||
|
||||
if firstLetter != previousFirstLetter {
|
||||
groups = append(groups, []*arn.Company{})
|
||||
currentGroupIndex++
|
||||
previousFirstLetter = firstLetter
|
||||
}
|
||||
|
||||
groups[currentGroupIndex] = append(groups[currentGroupIndex], company)
|
||||
}
|
||||
|
||||
return ctx.HTML(components.Companies(companies, user))
|
||||
return ctx.HTML(components.Companies(groups, user))
|
||||
}
|
||||
|
Reference in New Issue
Block a user