diff --git a/app/controllers/profiles_controller.rb b/app/controllers/profiles_controller.rb
index b520cad55..2eeac08a8 100644
--- a/app/controllers/profiles_controller.rb
+++ b/app/controllers/profiles_controller.rb
@@ -22,6 +22,6 @@ def update
private
def user_params
- params.require(:user).permit(:username, :password_challenge)
+ params.require(:user).permit(:username, :password_challenge, :stories_order)
end
end
diff --git a/app/controllers/stories_controller.rb b/app/controllers/stories_controller.rb
index a304dd614..d5b03747b 100644
--- a/app/controllers/stories_controller.rb
+++ b/app/controllers/stories_controller.rb
@@ -2,7 +2,8 @@
class StoriesController < ApplicationController
def index
- @unread_stories = authorization.scope(StoryRepository.unread)
+ order = current_user.stories_order
+ @unread_stories = authorization.scope(StoryRepository.unread(order:))
end
def update
diff --git a/app/models/user.rb b/app/models/user.rb
index 4424bf12d..587a6cc93 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -13,6 +13,8 @@ class User < ApplicationRecord
before_save :update_api_key
+ enum :stories_order, { desc: "desc", asc: "asc" }, prefix: true
+
attr_accessor :password_challenge
# `password_challenge` logic should be able to be removed in Rails 7.1
diff --git a/app/repositories/story_repository.rb b/app/repositories/story_repository.rb
index d50ac3d75..6ed97afb7 100644
--- a/app/repositories/story_repository.rb
+++ b/app/repositories/story_repository.rb
@@ -47,8 +47,8 @@ def self.exists?(id, feed_id)
Story.exists?(entry_id: id, feed_id:)
end
- def self.unread
- Story.where(is_read: false).order("published desc").includes(:feed)
+ def self.unread(order: "desc")
+ Story.where(is_read: false).order("published #{order}").includes(:feed)
end
def self.unread_since_id(since_id)
diff --git a/app/views/profiles/edit.html.erb b/app/views/profiles/edit.html.erb
index bd6db8db1..d8bc7c499 100644
--- a/app/views/profiles/edit.html.erb
+++ b/app/views/profiles/edit.html.erb
@@ -1,12 +1,20 @@
<%= t('.title') %>
-
+<%= form_with(model: user, url: profile_path) do |form| %>
+
+ <%= form.submit("Update") %>
+<% end %>
<%= form_with(model: user, url: profile_path) do |form| %>