Skip to content

Commit b57e1a1

Browse files
committed
Sort packages by installs
1 parent ae8e5db commit b57e1a1

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

internal/http/handlers.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func handleIndex(a *app.App, tmpl *templateSet) http.HandlerFunc {
5151
Sort: r.URL.Query().Get("sort"),
5252
}
5353
if filters.Sort == "" {
54-
filters.Sort = "downloads"
54+
filters.Sort = "composer_installs"
5555
}
5656
page, _ := strconv.Atoi(r.URL.Query().Get("page"))
5757
if page < 1 {
@@ -108,7 +108,7 @@ func handleIndexPartial(a *app.App, tmpl *templateSet) http.HandlerFunc {
108108
Sort: r.URL.Query().Get("sort"),
109109
}
110110
if filters.Sort == "" {
111-
filters.Sort = "downloads"
111+
filters.Sort = "composer_installs"
112112
}
113113
page, _ := strconv.Atoi(r.URL.Query().Get("page"))
114114
if page < 1 {
@@ -557,10 +557,10 @@ func queryPackages(ctx context.Context, db *sql.DB, f publicFilters, page, limit
557557
args = append(args, f.Type)
558558
}
559559

560-
orderBy := "active_installs DESC"
560+
orderBy := "wp_composer_installs_total DESC"
561561
switch f.Sort {
562-
case "composer_installs":
563-
orderBy = "wp_composer_installs_total DESC"
562+
case "active_installs":
563+
orderBy = "active_installs DESC"
564564
case "updated":
565565
orderBy = "last_committed DESC NULLS LAST"
566566
case "name":

internal/http/templates.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ func paginateURL(f publicFilters, page int) string {
111111
if f.Type != "" {
112112
v.Set("type", f.Type)
113113
}
114-
if f.Sort != "" && f.Sort != "downloads" {
114+
if f.Sort != "" && f.Sort != "composer_installs" {
115115
v.Set("sort", f.Sort)
116116
}
117117
if page > 1 {
@@ -132,7 +132,7 @@ func paginatePartialURL(f publicFilters, page int) string {
132132
if f.Type != "" {
133133
v.Set("type", f.Type)
134134
}
135-
if f.Sort != "" && f.Sort != "downloads" {
135+
if f.Sort != "" && f.Sort != "composer_installs" {
136136
v.Set("sort", f.Sort)
137137
}
138138
if page > 1 {

internal/http/templates/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ <h2 class="text-lg text-gray-500 max-w-xl mx-auto mb-8 text-balance">A modern, c
6767
</select>
6868
<label for="filter-sort" class="sr-only">Sort by</label>
6969
<select id="filter-sort" name="sort" class="h-10 pl-3 pr-8 text-sm border border-gray-200 rounded-lg bg-white select-chevron focus:outline-none focus:ring-2 focus:ring-brand-primary/20 focus:border-brand-primary">
70-
<option value="active_installs"{{if eq .Filters.Sort "active_installs"}} selected{{end}}>Active installs</option>
7170
<option value="composer_installs"{{if eq .Filters.Sort "composer_installs"}} selected{{end}}>Composer installs</option>
71+
<option value="active_installs"{{if eq .Filters.Sort "active_installs"}} selected{{end}}>Active installs</option>
7272
<option value="name"{{if eq .Filters.Sort "name"}} selected{{end}}>Name</option>
7373
<option value="updated"{{if eq .Filters.Sort "updated"}} selected{{end}}>Recently updated</option>
7474
</select>

0 commit comments

Comments
 (0)