add relay states to ui
Some checks failed
Rust / build (ubuntu-latest, stable) (push) Failing after 1m33s
Rust / build (ubuntu-latest, stable) (pull_request) Failing after 1m31s

This commit is contained in:
2026-02-11 17:46:10 +07:00
parent 9380288fc1
commit 836d9a99e1
10 changed files with 102 additions and 26 deletions

View File

@@ -23,7 +23,9 @@ use ui::divider::Divider;
use ui::indicator::Indicator;
use ui::input::{InputEvent, InputState, TextInput};
use ui::notification::Notification;
use ui::{h_flex, v_flex, Disableable, IconName, Selectable, Sizable, StyledExt, WindowExtension};
use ui::{
h_flex, v_flex, Disableable, Icon, IconName, Selectable, Sizable, StyledExt, WindowExtension,
};
mod entry;
@@ -635,10 +637,12 @@ impl Render for Sidebar {
.border_b_1()
.border_color(cx.theme().border_variant)
.child(
div()
h_flex()
.gap_0p5()
.text_xs()
.font_semibold()
.text_color(cx.theme().text_muted)
.child(Icon::new(IconName::ChevronDown))
.child(SharedString::from("Results")),
)
.child(
@@ -660,10 +664,12 @@ impl Render for Sidebar {
.gap_1()
.flex_1()
.child(
div()
h_flex()
.gap_0p5()
.text_xs()
.font_semibold()
.text_color(cx.theme().text_muted)
.child(Icon::new(IconName::ChevronDown))
.child(SharedString::from("Suggestions")),
)
.child(

View File

@@ -12,8 +12,8 @@ use gpui::{
use nostr_sdk::prelude::*;
use person::PersonRegistry;
use smallvec::{smallvec, SmallVec};
use state::NostrRegistry;
use theme::{SIDEBAR_WIDTH, TITLEBAR_HEIGHT};
use state::{NostrRegistry, RelayState};
use theme::{ActiveTheme, SIDEBAR_WIDTH, TITLEBAR_HEIGHT};
use titlebar::TitleBar;
use ui::avatar::Avatar;
use ui::button::{Button, ButtonVariants};
@@ -102,7 +102,7 @@ impl Workspace {
subscriptions.push(
// Observe the NIP-65 state
cx.observe(&nip65_state, move |this, state, cx| {
if state.read(cx).idle() {
if state.read(cx).idle() || state.read(cx).checking() {
this.get_current_user(cx);
}
}),
@@ -202,9 +202,12 @@ impl Workspace {
}
fn titlebar_left(&mut self, _window: &mut Window, cx: &Context<Self>) -> impl IntoElement {
let nostr = NostrRegistry::global(cx);
let nip65 = nostr.read(cx).nip65_state();
let nip17 = nostr.read(cx).nip17_state();
h_flex()
.h(TITLEBAR_HEIGHT)
.w(SIDEBAR_WIDTH)
.flex_shrink_0()
.justify_between()
.gap_2()
@@ -229,14 +232,51 @@ impl Workspace {
}),
)
})
}
fn titlebar_center(&mut self, _window: &mut Window, _cx: &Context<Self>) -> impl IntoElement {
h_flex().h(TITLEBAR_HEIGHT).flex_1()
.map(|this| match nip65.read(cx) {
RelayState::Checking => this.child(
div()
.text_xs()
.text_color(cx.theme().text_muted)
.child(SharedString::from("Fetching user's relay list...")),
),
RelayState::NotConfigured => this.child(
h_flex()
.h_6()
.w_full()
.px_1()
.text_xs()
.text_color(cx.theme().warning_foreground)
.bg(cx.theme().warning_background)
.rounded_xs()
.child(SharedString::from("User hasn't configured a relay list")),
),
_ => this,
})
.map(|this| match nip17.read(cx) {
RelayState::Checking => {
this.child(div().text_xs().text_color(cx.theme().text_muted).child(
SharedString::from("Fetching user's messaging relay list..."),
))
}
RelayState::NotConfigured => this.child(
h_flex()
.h_6()
.w_full()
.px_1()
.text_xs()
.text_color(cx.theme().warning_foreground)
.bg(cx.theme().warning_background)
.rounded_xs()
.child(SharedString::from(
"User hasn't configured a messaging relay list",
)),
),
_ => this,
})
}
fn titlebar_right(&mut self, _window: &mut Window, _cx: &Context<Self>) -> impl IntoElement {
h_flex().h(TITLEBAR_HEIGHT).w(SIDEBAR_WIDTH).flex_shrink_0()
h_flex().h(TITLEBAR_HEIGHT).flex_shrink_0()
}
}
@@ -247,12 +287,11 @@ impl Render for Workspace {
// Titlebar elements
let left = self.titlebar_left(window, cx).into_any_element();
let center = self.titlebar_center(window, cx).into_any_element();
let right = self.titlebar_right(window, cx).into_any_element();
// Update title bar children
self.titlebar.update(cx, |this, _cx| {
this.set_children(vec![left, center, right]);
this.set_children(vec![left, right]);
});
div()