Added companies sorted by popularity
This commit is contained in:
parent
e9f15eacbc
commit
cbf640710c
@ -10,8 +10,8 @@ import (
|
||||
"github.com/animenotifier/notify.moe/utils"
|
||||
)
|
||||
|
||||
// Get renders the companies page.
|
||||
func Get(ctx *aero.Context) string {
|
||||
// All renders the companies page.
|
||||
func All(ctx *aero.Context) string {
|
||||
user := utils.GetUser(ctx)
|
||||
|
||||
companies := arn.FilterCompanies(func(company *arn.Company) bool {
|
||||
|
@ -1,6 +1,21 @@
|
||||
component Companies(groups [][]*arn.Company, user *arn.User)
|
||||
h1 Companies
|
||||
CompaniesTabs(user)
|
||||
|
||||
.companies
|
||||
each group in groups
|
||||
.companies-group
|
||||
h3= group[0].Name.English[:1]
|
||||
|
||||
ul
|
||||
each company in group
|
||||
li.mountable
|
||||
a.ajax(href=company.Link())= company.Name.English
|
||||
|
||||
component CompaniesTabs(user *arn.User)
|
||||
.tabs
|
||||
Tab("All", "font", "/companies")
|
||||
Tab("Popular", "globe", "/companies/popular")
|
||||
|
||||
.corner-buttons
|
||||
if user != nil
|
||||
if user.DraftIndex().CompanyID == ""
|
||||
@ -10,14 +25,4 @@ component Companies(groups [][]*arn.Company, user *arn.User)
|
||||
else
|
||||
a.button.ajax(href="/company/" + user.DraftIndex().CompanyID + "/edit")
|
||||
Icon("pencil")
|
||||
span Edit draft
|
||||
|
||||
.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
|
||||
span Edit draft
|
57
pages/companies/popular.go
Normal file
57
pages/companies/popular.go
Normal file
@ -0,0 +1,57 @@
|
||||
package companies
|
||||
|
||||
import (
|
||||
"sort"
|
||||
|
||||
"github.com/aerogo/aero"
|
||||
"github.com/animenotifier/arn"
|
||||
"github.com/animenotifier/notify.moe/components"
|
||||
"github.com/animenotifier/notify.moe/utils"
|
||||
)
|
||||
|
||||
const maxPopularCompanies = 100
|
||||
|
||||
// Popular renders the companies sorted by popularity.
|
||||
func Popular(ctx *aero.Context) string {
|
||||
user := utils.GetUser(ctx)
|
||||
companies := []*arn.Company{}
|
||||
|
||||
// ID to popularity
|
||||
popularity := map[string]int{}
|
||||
|
||||
for anime := range arn.StreamAnime() {
|
||||
for _, studio := range anime.Studios() {
|
||||
popularity[studio.ID] += anime.Popularity.Watching + anime.Popularity.Completed
|
||||
}
|
||||
}
|
||||
|
||||
for companyID := range popularity {
|
||||
company, err := arn.GetCompany(companyID)
|
||||
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
companies = append(companies, company)
|
||||
}
|
||||
|
||||
sort.Slice(companies, func(i, j int) bool {
|
||||
a := companies[i]
|
||||
b := companies[j]
|
||||
|
||||
aPopularity := popularity[a.ID]
|
||||
bPopularity := popularity[b.ID]
|
||||
|
||||
if aPopularity == bPopularity {
|
||||
return a.Name.English < b.Name.English
|
||||
}
|
||||
|
||||
return aPopularity > bPopularity
|
||||
})
|
||||
|
||||
if len(companies) > maxPopularCompanies {
|
||||
companies = companies[:maxPopularCompanies]
|
||||
}
|
||||
|
||||
return ctx.HTML(components.PopularCompanies(companies, popularity, user))
|
||||
}
|
9
pages/companies/popular.pixy
Normal file
9
pages/companies/popular.pixy
Normal file
@ -0,0 +1,9 @@
|
||||
component PopularCompanies(companies []*arn.Company, popularity map[string]int, user *arn.User)
|
||||
CompaniesTabs(user)
|
||||
|
||||
.companies
|
||||
ol
|
||||
each company in companies
|
||||
li.mountable
|
||||
a.ajax(href=company.Link())= company.Name.English
|
||||
span= " (" + strconv.Itoa(popularity[company.ID]) + ")"
|
@ -105,7 +105,8 @@ func Configure(app *aero.Application) {
|
||||
// Companies
|
||||
l.Page("/company/:id", company.Get)
|
||||
l.Page("/company/:id/edit", company.Edit)
|
||||
l.Page("/companies", companies.Get)
|
||||
l.Page("/companies", companies.All)
|
||||
l.Page("/companies/popular", companies.Popular)
|
||||
|
||||
// Settings
|
||||
l.Page("/settings", settings.Get(components.SettingsPersonal))
|
||||
|
@ -17,6 +17,10 @@ strong
|
||||
em
|
||||
font-style italic
|
||||
|
||||
ol
|
||||
li
|
||||
list-style-type decimal
|
||||
|
||||
hr
|
||||
border none
|
||||
border-bottom 1px solid text-color
|
||||
|
Loading…
Reference in New Issue
Block a user