diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 2a3427fb..3830648a 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,5 +1,5 @@ class ApplicationController < ActionController::Base - include AutoSync, Authentication, Invitable, SelfHostable + include AutoSync, Authentication, Invitable, SelfHostable, StoreLocation include Pagy::Backend # Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has. diff --git a/app/controllers/concerns/store_location.rb b/app/controllers/concerns/store_location.rb new file mode 100644 index 00000000..2bf87a64 --- /dev/null +++ b/app/controllers/concerns/store_location.rb @@ -0,0 +1,31 @@ +module StoreLocation + extend ActiveSupport::Concern + + included do + helper_method :previous_path + before_action :store_return_to + after_action :clear_previous_path + end + + def previous_path + session[:return_to] || fallback_path + end + +private + + def store_return_to + if params[:return_to].present? + session[:return_to] = params[:return_to] + end + end + + def clear_previous_path + if request.fullpath == session[:return_to] + session.delete(:return_to) + end + end + + def fallback_path + root_path + end +end diff --git a/app/views/layouts/_sidebar.html.erb b/app/views/layouts/_sidebar.html.erb index 74cc5c64..0cec2340 100644 --- a/app/views/layouts/_sidebar.html.erb +++ b/app/views/layouts/_sidebar.html.erb @@ -30,7 +30,7 @@
- <%= link_to settings_profile_path, class: "flex gap-2 items-center hover:bg-gray-50 rounded-lg px-3 py-2" do %> + <%= link_to settings_profile_path(return_to: request.fullpath), class: "flex gap-2 items-center hover:bg-gray-50 rounded-lg px-3 py-2" do %> <%= lucide_icon("settings", class: "w-5 h-5 text-gray-500 shrink-0") %> Settings <% end %> diff --git a/app/views/settings/_nav.html.erb b/app/views/settings/_nav.html.erb index 7edaf8a8..f252c573 100644 --- a/app/views/settings/_nav.html.erb +++ b/app/views/settings/_nav.html.erb @@ -1,12 +1,12 @@
- <%= link_to return_to_path(params), class: "flex items-center gap-1 text-gray-900 font-medium text-sm" do %> + <%= link_to previous_path, class: "flex items-center gap-1 text-gray-900 font-medium text-sm" do %> <%= lucide_icon "chevron-left", class: "w-5 h-5 text-gray-500" %> Back <% end %> - + <%= link_to previous_path, class: "uppercase bg-gray-100 rounded-sm px-1 py-0.5 text-xs text-gray-500 shadow-sm ml-1 pointer-events-none", data: { controller: "hotkey", hotkey: "Escape" } do %> esc - + <% end %>