Skip to content

Commit e0d3747

Browse files
authored
Change default workshop sort to created (instead of title) (#549)
* Change default workshop sort to created (instead of title) * Fix test to expect created is the default sort
1 parent 4a9a963 commit e0d3747

File tree

4 files changed

+9
-8
lines changed

4 files changed

+9
-8
lines changed

app/controllers/workshops_controller.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
class WorkshopsController < ApplicationController
44

55
def index
6-
search_service = WorkshopSearchService.new(params, super_user: current_user.super_user?).call
7-
@sort = params[:sort] # search_service.default_sort
6+
search_service = WorkshopSearchService.new(params,
7+
super_user: current_user.super_user?).call
8+
@sort = search_service.sort
89

910
@workshops = search_service.workshops
1011
.includes(:categories, :sectors, :windows_type, :user, :images, :bookmarks)

app/services/workshop_search_service.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def call
1919

2020
# Compute the effective sort
2121
def default_sort
22-
params[:sort].presence || 'title'
22+
params[:sort].presence || "created"
2323
# return params[:sort] if params[:sort].present?
2424
# return 'keywords' if params[:query].present? # only when returning weighted results from # search_by_query
2525
# 'title'
@@ -153,7 +153,7 @@ def order_by_params
153153
when 'keywords'
154154
# already ordered in filter_by_query
155155
else
156-
@workshops = @workshops.order(title: :asc)
156+
@workshops = @workshops.order(created_at: :asc, title: :asc)
157157
end
158158
end
159159

app/views/workshops/_sort_by_options.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<div class="flex items-center gap-1">
22
<label class="flex items-center gap-1 cursor-pointer">
33
<%= radio_button_tag :sort, "created",
4-
@sort == "created" %>
4+
@sort == "created" || !params[:sort].present? %>
55
<span class="text-sm">Newest</span>
66
</label>
77
</div>
88

99
<div class="flex items-center gap-1">
1010
<label class="flex items-center gap-1 cursor-pointer">
1111
<%= radio_button_tag :sort, "title",
12-
@sort == "title" || !params[:sort].present? %>
12+
@sort == "title" %>
1313
<span class="text-sm">Title</span>
1414
</label>
1515
</div>

spec/services/workshop_search_service_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,9 @@
7373
expect(service.sort).to eq('keywords')
7474
end
7575

76-
it "defaults to title if no query or sort is provided" do
76+
it "defaults to created if no query or sort is provided" do
7777
service = WorkshopSearchService.new({}).call
78-
expect(service.sort).to eq('title')
78+
expect(service.sort).to eq('created')
7979
end
8080
end
8181
end

0 commit comments

Comments
 (0)