Improved company list
This commit is contained in:
parent
7d2136a973
commit
c53ab95e1e
@ -2,6 +2,7 @@ package companies
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"sort"
|
"sort"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/aerogo/aero"
|
"github.com/aerogo/aero"
|
||||||
"github.com/animenotifier/arn"
|
"github.com/animenotifier/arn"
|
||||||
@ -9,8 +10,6 @@ import (
|
|||||||
"github.com/animenotifier/notify.moe/utils"
|
"github.com/animenotifier/notify.moe/utils"
|
||||||
)
|
)
|
||||||
|
|
||||||
const maxEntries = 24
|
|
||||||
|
|
||||||
// Get renders the companies page.
|
// Get renders the companies page.
|
||||||
func Get(ctx *aero.Context) string {
|
func Get(ctx *aero.Context) string {
|
||||||
user := utils.GetUser(ctx)
|
user := utils.GetUser(ctx)
|
||||||
@ -20,12 +19,25 @@ func Get(ctx *aero.Context) string {
|
|||||||
})
|
})
|
||||||
|
|
||||||
sort.Slice(companies, func(i, j int) bool {
|
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 {
|
groups := [][]*arn.Company{}
|
||||||
companies = companies[:maxEntries]
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
return ctx.HTML(components.Companies(companies, user))
|
groups[currentGroupIndex] = append(groups[currentGroupIndex], company)
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
h1 Companies
|
||||||
|
|
||||||
.corner-buttons
|
.corner-buttons
|
||||||
@ -12,7 +12,12 @@ component Companies(companies []*arn.Company, user *arn.User)
|
|||||||
Icon("pencil")
|
Icon("pencil")
|
||||||
span Edit draft
|
span Edit draft
|
||||||
|
|
||||||
|
.companies
|
||||||
|
each group in groups
|
||||||
|
.companies-group
|
||||||
|
h3= group[0].Name.English[:1]
|
||||||
|
|
||||||
ul
|
ul
|
||||||
each company in companies
|
each company in group
|
||||||
li
|
li
|
||||||
a.ajax(href=company.Link())= company.Name.English
|
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