Badge every auto-added relay and the auto-added display name
CI / Test (pull_request) Successful in 1m18s
CI / Test (pull_request) Successful in 1m18s
When no relay list exists, all recommended relays are now marked as added, not just the site relay, with a short note explaining the default list. The profile editor likewise marks the display name as added when it is filled in from the account display name.
This commit is contained in:
6 files changed
+79
-13
No files matched your search
@@ -52,7 +52,27 @@
|
||||
<div class="grid grid-cols-1 gap-y-6 md:grid-cols-2 md:gap-x-8">
|
||||
<div>
|
||||
<%= render FormElements::FieldsetComponent.new(tag: "div", title: "Display name") do %>
|
||||
<%= f.text_field :display_name, value: @display_name, class: "w-full" %>
|
||||
<% if @display_name_added %>
|
||||
<div class="w-full flex flex-col" data-controller="field-suggestion"
|
||||
data-field-suggestion-added-value-value="<%= @user.display_name %>">
|
||||
<div class="relative">
|
||||
<%= f.text_field :display_name, value: @display_name,
|
||||
data: {
|
||||
:'field-suggestion-target' => "input",
|
||||
action: "input->field-suggestion#checkAdded"
|
||||
},
|
||||
class: "w-full pr-16 border-emerald-500 ring-1 ring-emerald-500 focus:border-emerald-500 focus:ring-emerald-500 bg-emerald-50/20" %>
|
||||
<span class="absolute inset-y-0 right-2.5 flex items-center pointer-events-none"
|
||||
data-field-suggestion-target="badge">
|
||||
<span class="rounded-full bg-emerald-100 px-2 py-0.5 text-xs font-semibold text-emerald-800">
|
||||
added
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<% else %>
|
||||
<%= f.text_field :display_name, value: @display_name, class: "w-full" %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<%= render FormElements::FieldsetComponent.new(tag: "div", title: "About") do %>
|
||||
<%= f.text_area :about, value: @about, rows: 3, class: "w-full" %>
|
||||
|
||||
@@ -17,9 +17,11 @@ module Settings
|
||||
@profile = JSON.parse(profile_event["content"]) rescue {}
|
||||
end
|
||||
|
||||
@display_name = NostrManagerService::DISPLAY_NAME_KEYS
|
||||
@profile_display_name = NostrManagerService::DISPLAY_NAME_KEYS
|
||||
.map { |key| @profile[key] }
|
||||
.find(&:present?) || @user.display_name
|
||||
.find(&:present?)
|
||||
@display_name = @profile_display_name || @user.display_name
|
||||
@display_name_added = @profile_display_name.blank? && @user.display_name.present?
|
||||
|
||||
@about = @profile["about"] if @profile["about"].is_a?(String)
|
||||
@website = @profile["website"] if @profile["website"].is_a?(String)
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
<div class="w-[72vw] md:w-[500px]">
|
||||
<h3 class="mb-6">Edit relays</h3>
|
||||
<% if @nip65_event.blank? %>
|
||||
<p class="mb-4 text-gray-500">
|
||||
These are the servers that your Nostr apps will publish to. Here's a recommended list to start with:
|
||||
</p>
|
||||
<% end %>
|
||||
<%= form_with url: "#", local: true,
|
||||
html: { data: {
|
||||
controller: "url-list-editor",
|
||||
|
||||
@@ -14,7 +14,7 @@ module Settings
|
||||
normalized_site_relay = NostrManagerService.normalize_url(site_relay)
|
||||
|
||||
if @nip65_event.blank?
|
||||
relays = Setting.nostr_discovery_relays.map { |url| { url: url, marker: nil, added: false } }
|
||||
relays = Setting.nostr_discovery_relays.map { |url| { url: url, marker: nil, added: true } }
|
||||
if site_relay.present?
|
||||
relays.reject! { |r| NostrManagerService.normalize_url(r[:url]) == normalized_site_relay }
|
||||
relays.unshift({ url: site_relay, marker: nil, added: true })
|
||||
|
||||
@@ -271,9 +271,14 @@ RSpec.describe Settings::NostrEditProfileComponent, type: :component do
|
||||
end
|
||||
|
||||
describe "when profile event is missing or fields are empty" do
|
||||
it "prefills NIP-05 and Lightning addresses with user address and marks them as added" do
|
||||
it "prefills the display name, NIP-05 and Lightning addresses and marks them as added" do
|
||||
rendered = render_inline(described_class.new(user: user, profile_event: nil))
|
||||
|
||||
display_name_input = rendered.css("input[name='user[display_name]']").first
|
||||
expect(display_name_input["value"]).to eq("Alice Wonderland")
|
||||
expect(display_name_input["class"]).to include("border-emerald-500")
|
||||
expect(display_name_input["data-action"]).to include("input->field-suggestion#checkAdded")
|
||||
|
||||
nip05_input = rendered.css("input[name='user[nip05_address]']").first
|
||||
expect(nip05_input["value"]).to eq("alice@kosmos.org")
|
||||
expect(nip05_input["class"]).to include("border-emerald-500")
|
||||
@@ -285,7 +290,22 @@ RSpec.describe Settings::NostrEditProfileComponent, type: :component do
|
||||
expect(lud16_input["data-action"]).to include("input->field-suggestion#checkAdded")
|
||||
|
||||
badges = rendered.css("span.rounded-full").select { |el| el.text.strip == "added" }
|
||||
expect(badges.size).to eq(2)
|
||||
expect(badges.size).to eq(3)
|
||||
end
|
||||
|
||||
context "without an account display name" do
|
||||
before { allow(user).to receive(:display_name).and_return(nil) }
|
||||
|
||||
it "does not mark the display name as added" do
|
||||
rendered = render_inline(described_class.new(user: user, profile_event: nil))
|
||||
|
||||
display_name_input = rendered.css("input[name='user[display_name]']").first
|
||||
expect(display_name_input["value"]).to be_blank
|
||||
expect(display_name_input["class"]).not_to include("border-emerald-500")
|
||||
|
||||
badges = rendered.css("span.rounded-full").select { |el| el.text.strip == "added" }
|
||||
expect(badges.size).to eq(2)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -303,6 +323,11 @@ RSpec.describe Settings::NostrEditProfileComponent, type: :component do
|
||||
it "shows current values with different badges and suggestion strips" do
|
||||
rendered = render_inline(described_class.new(user: user, profile_event: profile_event))
|
||||
|
||||
display_name_input = rendered.css("input[name='user[display_name]']").first
|
||||
expect(display_name_input["value"]).to eq("Alice External")
|
||||
expect(display_name_input["class"]).not_to include("border-emerald-500")
|
||||
expect(display_name_input["class"]).not_to include("border-amber-400")
|
||||
|
||||
nip05_input = rendered.css("input[name='user[nip05_address]']").first
|
||||
expect(nip05_input["value"]).to eq("alice@other.org")
|
||||
expect(nip05_input["class"]).to include("border-amber-400")
|
||||
|
||||
@@ -27,7 +27,7 @@ RSpec.describe Settings::NostrEditRelaysComponent, type: :component do
|
||||
end
|
||||
|
||||
describe "when user has no relay list (nip65_event is nil)" do
|
||||
it "prepends the site relay as added and suggests discovery relays without a badge" do
|
||||
it "marks the site relay and every discovery relay as added" do
|
||||
rendered = render_inline(described_class.new(nip65_event: nil))
|
||||
|
||||
list = rendered.css("[data-url-list-editor-target='list']").first
|
||||
@@ -39,14 +39,21 @@ RSpec.describe Settings::NostrEditRelaysComponent, type: :component do
|
||||
])
|
||||
|
||||
badges = rendered.css("span.rounded-full").select { |el| el.text.strip == "added" }
|
||||
expect(badges.size).to eq(1)
|
||||
expect(badges.size).to eq(3)
|
||||
|
||||
site_input = rendered.css("input[value='wss://nostr.kosmos.org']").first
|
||||
expect(site_input["data-added-value"]).to eq("wss://nostr.kosmos.org")
|
||||
relay_inputs.each do |url|
|
||||
input = rendered.css("input[value='#{url}']").first
|
||||
expect(input["data-added-value"]).to eq(url)
|
||||
expect(input["class"]).to include("border-emerald-500")
|
||||
expect(input["data-action"]).to include("input->url-list-editor#checkAdded")
|
||||
end
|
||||
end
|
||||
|
||||
suggestion_input = rendered.css("input[value='wss://nos.lol']").first
|
||||
expect(suggestion_input["data-added-value"]).to be_nil
|
||||
expect(suggestion_input["class"]).not_to include("border-emerald-500")
|
||||
it "shows a hint recommending the default list" do
|
||||
rendered = render_inline(described_class.new(nip65_event: nil))
|
||||
|
||||
hint = rendered.css("p").find { |el| el.text.include?("recommended list to start with") }
|
||||
expect(hint).to be_present
|
||||
end
|
||||
end
|
||||
|
||||
@@ -82,6 +89,13 @@ RSpec.describe Settings::NostrEditRelaysComponent, type: :component do
|
||||
select = rendered.css("select[name='relay_markers[]']").first
|
||||
expect(select["class"]).to include("w-36")
|
||||
end
|
||||
|
||||
it "does not show the recommended-list hint" do
|
||||
rendered = render_inline(described_class.new(nip65_event: nip65_event))
|
||||
|
||||
hint = rendered.css("p").find { |el| el.text.include?("recommended list to start with") }
|
||||
expect(hint).to be_nil
|
||||
end
|
||||
end
|
||||
|
||||
describe "when user already has site relay in their relay list" do
|
||||
|
||||
Reference in new issue
Block a user