Improved company list
This commit is contained in:
parent
7d2136a973
commit
c53ab95e1e
@ -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))
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
component Companies(companies []*arn.Company, user *arn.User)
|
||||
component Companies(groups [][]*arn.Company, user *arn.User)
|
||||
h1 Companies
|
||||
|
||||
.corner-buttons
|
||||
@ -12,7 +12,12 @@ component Companies(companies []*arn.Company, user *arn.User)
|
||||
Icon("pencil")
|
||||
span Edit draft
|
||||
|
||||
ul
|
||||
each company in companies
|
||||
li
|
||||
a.ajax(href=company.Link())= company.Name.English
|
||||
.companies
|
||||
each group in groups
|
||||
.companies-group
|
||||
h3= group[0].Name.English[:1]
|
||||
|
||||
ul
|
||||
each company in group
|
||||
li
|
||||
a.ajax(href=company.Link())= company.Name.English
|
5
pages/companies/companies.scarlet
Normal file
5
pages/companies/companies.scarlet
Normal file
@ -0,0 +1,5 @@
|
||||
.companies
|
||||
//
|
||||
|
||||
.companies-group
|
||||
//
|
Loading…
Reference in New Issue
Block a user