Skip to content

armgit / maybe

Public Imported from GitHub
0

The personal finance app for everyone

Fix: Escape button not being handled on settings pages (#1210)

Jestin Palamuttam23786b444a3d
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 @@
</div>
</div>
<div class="border-t border-b border-alpha-black-100 p-1">
- <%= 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") %>
<span class="text-gray-900 text-sm">Settings</span>
<% 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 @@
<div class="space-y-4">
<div class="flex items-center gap-2 p-2">
- <%= 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" %>
<span>Back</span>
<% end %>
- <span data-controller="hotkey" data-hotkey="Escape" data-action="hotkey#navigateBack" class="uppercase bg-gray-100 rounded-sm px-1 py-0.5 text-xs text-gray-500 shadow-sm ml-1">
+ <%= 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
- </span>
+ <% end %>
</div>
<nav class="space-y-4">
<section class="space-y-2">
diff --git a/test/system/settings_test.rb b/test/system/settings_test.rb
index 10d09663..32f2b8c8 100644
--- a/test/system/settings_test.rb
+++ b/test/system/settings_test.rb
@@ -21,7 +21,7 @@ class SettingsTest < ApplicationSystemTestCase
VCR.use_cassette("git_repository_provider/fetch_latest_release_notes") do
open_settings_from_sidebar
assert_selector "h1", text: "Account"
- assert_current_path settings_profile_path
+ assert_current_path settings_profile_path, ignore_query: true
@settings_links.each do |name, path|
click_link name