Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/controllers/workshops_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
class WorkshopsController < ApplicationController

def index
search_service = WorkshopSearchService.new(params, super_user: current_user.super_user?).call
@sort = params[:sort] # search_service.default_sort
search_service = WorkshopSearchService.new(params,
super_user: current_user.super_user?).call
@sort = search_service.sort

@workshops = search_service.workshops
.includes(:categories, :sectors, :windows_type, :user, :images, :bookmarks)
Expand Down
4 changes: 2 additions & 2 deletions app/services/workshop_search_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def call

# Compute the effective sort
def default_sort
params[:sort].presence || 'title'
params[:sort].presence || "created"
# return params[:sort] if params[:sort].present?
# return 'keywords' if params[:query].present? # only when returning weighted results from # search_by_query
# 'title'
Expand Down Expand Up @@ -153,7 +153,7 @@ def order_by_params
when 'keywords'
# already ordered in filter_by_query
else
@workshops = @workshops.order(title: :asc)
@workshops = @workshops.order(created_at: :asc, title: :asc)
end
end

Expand Down
4 changes: 2 additions & 2 deletions app/views/workshops/_sort_by_options.html.erb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<div class="flex items-center gap-1">
<label class="flex items-center gap-1 cursor-pointer">
<%= radio_button_tag :sort, "created",
@sort == "created" %>
@sort == "created" || !params[:sort].present? %>
<span class="text-sm">Newest</span>
</label>
</div>

<div class="flex items-center gap-1">
<label class="flex items-center gap-1 cursor-pointer">
<%= radio_button_tag :sort, "title",
@sort == "title" || !params[:sort].present? %>
@sort == "title" %>
<span class="text-sm">Title</span>
</label>
</div>
Expand Down
4 changes: 2 additions & 2 deletions spec/services/workshop_search_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@
expect(service.sort).to eq('keywords')
end

it "defaults to title if no query or sort is provided" do
it "defaults to created if no query or sort is provided" do
service = WorkshopSearchService.new({}).call
expect(service.sort).to eq('title')
expect(service.sort).to eq('created')
end
end
end
Expand Down