Collapse the Nostr Connect section when the account has a key
On the Nostr settings page, fold the Nostr Connect section into a closed details/summary, marked with a green dot while a signer is connected. Without a linked key the section stays expanded so connecting stays prominent.
This commit is contained in:
5 files changed
+57
-6
No files matched your search
@@ -1,6 +1,10 @@
|
||||
<section class="<%= section_class %>">
|
||||
<%= content_tag(@collapsible ? :details : :section, class: section_class) do %>
|
||||
<% if @title.present? %>
|
||||
<h4 class="<%= title_class %>"><%= @title %></h4>
|
||||
<% if @collapsible %>
|
||||
<summary class="<%= title_class %>"><%= @title %><% if show_connected_dot? %><span class="ml-2 inline-block h-2 w-2 rounded-full bg-emerald-500 align-middle" aria-hidden="true"></span><% end %></summary>
|
||||
<% else %>
|
||||
<h4 class="<%= title_class %>"><%= @title %></h4>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
<% if @description.present? %>
|
||||
@@ -176,4 +180,4 @@
|
||||
<% end %>
|
||||
</details>
|
||||
<% end %>
|
||||
</section>
|
||||
<% end %>
|
||||
@@ -3,7 +3,7 @@ require "rqrcode"
|
||||
class NostrSignerConnectComponent < ViewComponent::Base
|
||||
def initialize(pending_session: nil, active_session: nil, create_url:, destroy_url: nil,
|
||||
status_url: nil, replace_url: nil, title: "Nostr Connect", description: nil,
|
||||
show_disconnect: true, modal: false)
|
||||
show_disconnect: true, modal: false, collapsible: false)
|
||||
@pending_session = pending_session
|
||||
@active_session = active_session
|
||||
@create_url = create_url
|
||||
@@ -14,6 +14,7 @@ class NostrSignerConnectComponent < ViewComponent::Base
|
||||
@description = description
|
||||
@show_disconnect = show_disconnect
|
||||
@modal = modal
|
||||
@collapsible = collapsible
|
||||
end
|
||||
|
||||
def section_class
|
||||
@@ -23,7 +24,14 @@ class NostrSignerConnectComponent < ViewComponent::Base
|
||||
end
|
||||
|
||||
def title_class
|
||||
@modal ? "mb-1 text-xl font-bold" : "mb-0"
|
||||
return "mb-1 text-xl font-bold" if @modal
|
||||
return "cursor-pointer font-bold leading-6" if @collapsible
|
||||
|
||||
"mb-0"
|
||||
end
|
||||
|
||||
def show_connected_dot?
|
||||
@collapsible && @active_session.present?
|
||||
end
|
||||
|
||||
def text_class
|
||||
|
||||
@@ -114,7 +114,8 @@
|
||||
<%= render NostrSignerConnectComponent.new(
|
||||
active_session: active_nostr_signer_session,
|
||||
create_url: nostr_signer_settings_path,
|
||||
destroy_url: nostr_signer_settings_path
|
||||
destroy_url: nostr_signer_settings_path,
|
||||
collapsible: current_user.nostr_pubkey.present?
|
||||
) %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
@@ -150,6 +150,37 @@ RSpec.describe NostrSignerConnectComponent, type: :component do
|
||||
expect(connect["class"]).to include("btn-gray")
|
||||
end
|
||||
|
||||
it "wraps the section in a closed details with a connected dot when collapsible" do
|
||||
rendered = render_inline(
|
||||
described_class.new(
|
||||
active_session: active_session,
|
||||
create_url: "/settings/nostr_signer",
|
||||
collapsible: true
|
||||
)
|
||||
)
|
||||
|
||||
details = rendered.css("details").first
|
||||
expect(details).to be_present
|
||||
expect(details["open"]).to be_nil
|
||||
expect(rendered.css("section")).to be_empty
|
||||
expect(rendered.css("h4")).to be_empty
|
||||
|
||||
summary = details.css("summary").first
|
||||
expect(summary.text).to include("Nostr Connect")
|
||||
expect(summary["class"]).to include("cursor-pointer")
|
||||
expect(summary.css("span.rounded-full.bg-emerald-500").any?).to be(true)
|
||||
end
|
||||
|
||||
it "omits the connected dot when collapsible without an active session" do
|
||||
rendered = render_inline(
|
||||
described_class.new(create_url: "/settings/nostr_signer", collapsible: true)
|
||||
)
|
||||
|
||||
expect(rendered.css("details[open]")).to be_empty
|
||||
expect(rendered.css("summary").first.text).to include("Nostr Connect")
|
||||
expect(rendered.css("span.rounded-full.bg-emerald-500")).to be_empty
|
||||
end
|
||||
|
||||
it "renders a hidden replace dialog when a replace URL is given" do
|
||||
pending_session = instance_double(
|
||||
NostrSignerSession,
|
||||
|
||||
@@ -36,6 +36,13 @@ RSpec.describe 'Nostr Settings', type: :feature do
|
||||
.and_return("ce273cbfb0d4e3e06930773a337c1459e4849efd4cb4c751b906a561c98a6d09")
|
||||
end
|
||||
|
||||
scenario 'Collapses the Nostr Connect section' do
|
||||
visit setting_path(:nostr)
|
||||
|
||||
expect(page).to have_css("details > summary", text: "Nostr Connect")
|
||||
expect(page).not_to have_button("Connect a signer app")
|
||||
end
|
||||
|
||||
scenario 'Remove nostr pubkey from account' do
|
||||
visit setting_path(:nostr)
|
||||
expect(page).to have_field("nostr_public_key",
|
||||
|
||||
Reference in new issue
Block a user