From c53ab95e1ea304f5197bfcb986c0da8eb195b57b Mon Sep 17 00:00:00 2001 From: Eduard Urbach Date: Wed, 29 Nov 2017 15:26:11 +0100 Subject: [PATCH] Improved company list --- pages/companies/companies.go | 24 ++++++++++++++++++------ pages/companies/companies.pixy | 15 ++++++++++----- pages/companies/companies.scarlet | 5 +++++ 3 files changed, 33 insertions(+), 11 deletions(-) create mode 100644 pages/companies/companies.scarlet diff --git a/pages/companies/companies.go b/pages/companies/companies.go index 5d3a54b2..9461b96f 100644 --- a/pages/companies/companies.go +++ b/pages/companies/companies.go @@ -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)) } diff --git a/pages/companies/companies.pixy b/pages/companies/companies.pixy index 5dae8301..4f3ba796 100644 --- a/pages/companies/companies.pixy +++ b/pages/companies/companies.pixy @@ -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 \ No newline at end of file + .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 \ No newline at end of file diff --git a/pages/companies/companies.scarlet b/pages/companies/companies.scarlet new file mode 100644 index 00000000..6291f0ef --- /dev/null +++ b/pages/companies/companies.scarlet @@ -0,0 +1,5 @@ +.companies + // + +.companies-group + // \ No newline at end of file