diff --git a/app/controllers/content_controller.rb b/app/controllers/content_controller.rb index fbcb461c..5b6bec89 100644 --- a/app/controllers/content_controller.rb +++ b/app/controllers/content_controller.rb @@ -54,7 +54,16 @@ class ContentController < ApplicationController @content.select!(&:favorite?) end - @content = @content.sort_by {|x| [x.favorite? ? 0 : 1, x.name] } + # Sort content with favorites always first, then by selected sort option + sort_option = params[:sort] || 'updated_at' + @content = case sort_option + when 'alphabetical' + @content.sort_by { |x| [x.favorite? ? 0 : 1, x.name.downcase] } + when 'created_at' + @content.sort_by { |x| [x.favorite? ? 0 : 1, x.created_at] }.reverse + else # 'updated_at' or default + @content.sort_by { |x| [x.favorite? ? 0 : 1, x.updated_at] }.reverse + end @folders = current_user .folders .where(context: @content_type_name, parent_folder_id: nil) diff --git a/app/views/content/display/_tailwind_foldered_index.html.erb b/app/views/content/display/_tailwind_foldered_index.html.erb index e77d7bb3..7e04d7b7 100644 --- a/app/views/content/display/_tailwind_foldered_index.html.erb +++ b/app/views/content/display/_tailwind_foldered_index.html.erb @@ -451,33 +451,47 @@