mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-19 13:19:39 +02:00
Fix: Escape button not being handled on settings pages (#1210)
* fix: escape button handler * feat: location logic for settings page * fix: linting errors * fix: linting error * refactor: settings test
This commit is contained in:
parent
edbf4eb3d6
commit
23786b444a
5 changed files with 37 additions and 6 deletions
|
@ -1,5 +1,5 @@
|
||||||
class ApplicationController < ActionController::Base
|
class ApplicationController < ActionController::Base
|
||||||
include AutoSync, Authentication, Invitable, SelfHostable
|
include AutoSync, Authentication, Invitable, SelfHostable, StoreLocation
|
||||||
include Pagy::Backend
|
include Pagy::Backend
|
||||||
|
|
||||||
# Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has.
|
# Only allow modern browsers supporting webp images, web push, badges, import maps, CSS nesting, and CSS :has.
|
||||||
|
|
31
app/controllers/concerns/store_location.rb
Normal file
31
app/controllers/concerns/store_location.rb
Normal file
|
@ -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
|
|
@ -30,7 +30,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="border-t border-b border-alpha-black-100 p-1">
|
<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") %>
|
<%= lucide_icon("settings", class: "w-5 h-5 text-gray-500 shrink-0") %>
|
||||||
<span class="text-gray-900 text-sm">Settings</span>
|
<span class="text-gray-900 text-sm">Settings</span>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
<div class="space-y-4">
|
<div class="space-y-4">
|
||||||
<div class="flex items-center gap-2 p-2">
|
<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" %>
|
<%= lucide_icon "chevron-left", class: "w-5 h-5 text-gray-500" %>
|
||||||
<span>Back</span>
|
<span>Back</span>
|
||||||
<% end %>
|
<% 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
|
esc
|
||||||
</span>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
<nav class="space-y-4">
|
<nav class="space-y-4">
|
||||||
<section class="space-y-2">
|
<section class="space-y-2">
|
||||||
|
|
|
@ -21,7 +21,7 @@ class SettingsTest < ApplicationSystemTestCase
|
||||||
VCR.use_cassette("git_repository_provider/fetch_latest_release_notes") do
|
VCR.use_cassette("git_repository_provider/fetch_latest_release_notes") do
|
||||||
open_settings_from_sidebar
|
open_settings_from_sidebar
|
||||||
assert_selector "h1", text: "Account"
|
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|
|
@settings_links.each do |name, path|
|
||||||
click_link name
|
click_link name
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue