clean up
This commit is contained in:
@@ -10,7 +10,6 @@ use gpui::{
|
||||
Window, div, px, uniform_list,
|
||||
};
|
||||
use gpui_kit::assets::IconName;
|
||||
use gpui_kit::base::StyledExt as _;
|
||||
use gpui_kit::component::button::{Button, ButtonVariants};
|
||||
use gpui_kit::component::dock::{DockArea, DockPlacement, PanelHandle};
|
||||
use gpui_kit::component::input::{Input, InputEvent, InputState};
|
||||
@@ -205,6 +204,7 @@ impl NewChat {
|
||||
|
||||
Ok(())
|
||||
}));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -369,15 +369,13 @@ impl NewChat {
|
||||
.p_0p5()
|
||||
.rounded_full()
|
||||
.bg(cx.theme().secondary)
|
||||
.text_xs()
|
||||
.font_medium()
|
||||
.hover(|this| this.bg(cx.theme().primary))
|
||||
.child(
|
||||
Avatar::new(profile.avatar())
|
||||
.seed(profile.avatar_seed())
|
||||
.xsmall(),
|
||||
)
|
||||
.child(div().max_w_32().truncate().child(profile.name()))
|
||||
.child(div().max_w_32().truncate().text_xs().child(profile.name()))
|
||||
.on_click(cx.listener(move |this, _event, _window, cx| {
|
||||
this.toggle_member(&public_key, cx);
|
||||
}))
|
||||
|
||||
@@ -4,17 +4,17 @@ use anyhow::Error;
|
||||
use chat::{ChatRegistry, Room, RoomKind};
|
||||
use gpui::prelude::FluentBuilder;
|
||||
use gpui::{
|
||||
App, AppContext, ClipboardItem, Context, Div, Entity, IntoElement, ParentElement, Render,
|
||||
SharedString, Styled, Task, Window, div, retain_all,
|
||||
App, AppContext, Context, Div, Entity, IntoElement, ParentElement, Render, SharedString,
|
||||
Styled, Task, Window, div, retain_all,
|
||||
};
|
||||
use gpui_kit::assets::IconName;
|
||||
use gpui_kit::base::StyledExt as _;
|
||||
use gpui_kit::component::button::{Button, ButtonVariants};
|
||||
use gpui_kit::component::clipboard::Clipboard;
|
||||
use gpui_kit::component::dock::DockPlacement;
|
||||
use gpui_kit::component::input::{Input, InputState, Textarea, TextareaState};
|
||||
use gpui_kit::component::notification::Notification;
|
||||
use gpui_kit::component::{ActiveTheme, Disableable, Sizable, WindowExt, h_flex, v_flex};
|
||||
use instant::Duration;
|
||||
use nostr_sdk::prelude::*;
|
||||
use person::{Directory, Person, PersonRegistry, shorten_pubkey};
|
||||
use settings::AppSettings;
|
||||
@@ -49,8 +49,6 @@ struct ProfileDialog {
|
||||
website_input: Entity<InputState>,
|
||||
/// Uploading state
|
||||
uploading: bool,
|
||||
/// Copied states
|
||||
copied: bool,
|
||||
/// Updating state
|
||||
updating: bool,
|
||||
/// Tasks
|
||||
@@ -92,7 +90,6 @@ impl ProfileDialog {
|
||||
bio_input,
|
||||
website_input,
|
||||
uploading: false,
|
||||
copied: false,
|
||||
updating: false,
|
||||
tasks: vec![],
|
||||
}
|
||||
@@ -141,35 +138,6 @@ impl ProfileDialog {
|
||||
cx.notify();
|
||||
}
|
||||
|
||||
fn copy(&mut self, value: String, window: &mut Window, cx: &mut Context<Self>) {
|
||||
let item = ClipboardItem::new_string(value);
|
||||
cx.write_to_clipboard(item);
|
||||
|
||||
self.set_copied(true, window, cx);
|
||||
}
|
||||
|
||||
fn set_copied(&mut self, status: bool, window: &mut Window, cx: &mut Context<Self>) {
|
||||
self.copied = status;
|
||||
cx.notify();
|
||||
|
||||
if status {
|
||||
self.tasks.push(cx.spawn_in(window, async move |this, cx| {
|
||||
cx.background_executor().timer(Duration::from_secs(2)).await;
|
||||
|
||||
// Reset the copied state after a delay
|
||||
cx.update(|window, cx| {
|
||||
this.update(cx, |this, cx| {
|
||||
this.set_copied(false, window, cx);
|
||||
})
|
||||
.ok();
|
||||
})
|
||||
.ok();
|
||||
|
||||
Ok(())
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
fn set_uploading(&mut self, status: bool, cx: &mut Context<Self>) {
|
||||
self.uploading = status;
|
||||
cx.notify();
|
||||
@@ -368,7 +336,8 @@ impl Render for ProfileDialog {
|
||||
.w_full()
|
||||
.items_center()
|
||||
.justify_center()
|
||||
.bg(cx.theme().sidebar)
|
||||
.rounded(cx.theme().radius_lg)
|
||||
.bg(cx.theme().muted)
|
||||
.child(Avatar::new(avatar).seed(profile.avatar_seed()).large())
|
||||
.when(self.editing, |this| {
|
||||
this.child(
|
||||
@@ -393,25 +362,13 @@ impl Render for ProfileDialog {
|
||||
.justify_center()
|
||||
.gap_3()
|
||||
.rounded(cx.theme().radius)
|
||||
.bg(cx.theme().sidebar)
|
||||
.bg(cx.theme().muted)
|
||||
.text_xs()
|
||||
.child(shorten_pkey)
|
||||
.child(
|
||||
Button::new("copy")
|
||||
.icon({
|
||||
if self.copied {
|
||||
IconName::CircleCheck
|
||||
} else {
|
||||
IconName::Copy
|
||||
}
|
||||
})
|
||||
.xsmall()
|
||||
.secondary()
|
||||
.on_click(cx.listener(move |this, _ev, window, cx| {
|
||||
let pk = this.public_key.to_bech32().unwrap();
|
||||
this.copy(pk, window, cx)
|
||||
})),
|
||||
),
|
||||
.child(Clipboard::new("copy").value_fn({
|
||||
let public_key = self.public_key;
|
||||
move |_, _| public_key.to_bech32().unwrap_or_default().into()
|
||||
})),
|
||||
),
|
||||
)
|
||||
.when(self.editing, |this| {
|
||||
@@ -544,7 +501,7 @@ fn field(
|
||||
};
|
||||
|
||||
v_flex()
|
||||
.gap_1p5()
|
||||
.gap_1()
|
||||
.child(label(text, cx))
|
||||
.child(div().text_xs().text_color(color).child(content))
|
||||
.child(div().text_sm().text_color(color).child(content))
|
||||
}
|
||||
|
||||
@@ -264,7 +264,7 @@ impl RelayManager {
|
||||
|
||||
fn render_tab_bar(&self, cx: &mut Context<Self>) -> impl IntoElement {
|
||||
TabBar::new("relays-tabs")
|
||||
.segmented()
|
||||
.pill()
|
||||
.selected_index(self.active_tab)
|
||||
.on_click(cx.listener(|this, ix: &usize, _window, cx| {
|
||||
this.active_tab = *ix;
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
use anyhow::Error;
|
||||
use gpui::{
|
||||
App, AppContext, ClipboardItem, Context, Entity, EventEmitter, FocusHandle, Focusable,
|
||||
IntoElement, ParentElement, Render, SharedString, Styled, Task, Window, div,
|
||||
App, AppContext, Context, Entity, EventEmitter, FocusHandle, Focusable, IntoElement,
|
||||
ParentElement, Render, SharedString, Styled, Task, Window, div,
|
||||
};
|
||||
use gpui_kit::assets::IconName;
|
||||
use gpui_kit::base::StyledExt as _;
|
||||
use gpui_kit::component::button::{Button, ButtonVariants};
|
||||
use gpui_kit::component::clipboard::Clipboard;
|
||||
use gpui_kit::component::dock::{Panel, PanelEvent};
|
||||
use gpui_kit::component::input::{Input, InputState};
|
||||
use gpui_kit::component::separator::Separator;
|
||||
use gpui_kit::component::{ActiveTheme, Sizable, v_flex};
|
||||
use instant::Duration;
|
||||
use gpui_kit::component::{ActiveTheme, v_flex};
|
||||
use nostr_sdk::prelude::*;
|
||||
use state::USER_KEYRING;
|
||||
|
||||
@@ -32,9 +30,6 @@ pub struct BackupPanel {
|
||||
/// Secret key input
|
||||
nsec_input: Entity<InputState>,
|
||||
|
||||
/// Copied status
|
||||
copied: bool,
|
||||
|
||||
/// Background tasks
|
||||
tasks: Vec<Task<Result<(), Error>>>,
|
||||
}
|
||||
@@ -54,7 +49,6 @@ impl BackupPanel {
|
||||
focus_handle: cx.focus_handle(),
|
||||
npub_input,
|
||||
nsec_input,
|
||||
copied: false,
|
||||
tasks: vec![],
|
||||
}
|
||||
}
|
||||
@@ -81,31 +75,6 @@ impl BackupPanel {
|
||||
Ok(())
|
||||
}));
|
||||
}
|
||||
|
||||
fn copy_secret(&mut self, cx: &mut Context<Self>) {
|
||||
let value = self.nsec_input.read(cx).value();
|
||||
let item = ClipboardItem::new_string(value.to_string());
|
||||
cx.write_to_clipboard(item);
|
||||
|
||||
// Set the copied status to true
|
||||
self.set_copied(true, cx);
|
||||
}
|
||||
|
||||
fn set_copied(&mut self, status: bool, cx: &mut Context<Self>) {
|
||||
self.copied = status;
|
||||
cx.notify();
|
||||
|
||||
self.tasks.push(cx.spawn(async move |this, cx| {
|
||||
cx.background_executor().timer(Duration::from_secs(2)).await;
|
||||
|
||||
// Clear the error message after a delay
|
||||
this.update(cx, |this, cx| {
|
||||
this.set_copied(false, cx);
|
||||
})?;
|
||||
|
||||
Ok(())
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
impl gpui_kit::component::dock::BasePanel for BackupPanel {
|
||||
@@ -174,20 +143,12 @@ impl Render for BackupPanel {
|
||||
.child(Input::new(&self.nsec_input).disabled(true)),
|
||||
)
|
||||
.child(
|
||||
Button::new("copy")
|
||||
.icon(IconName::Copy)
|
||||
.label({
|
||||
if self.copied {
|
||||
"Copied"
|
||||
} else {
|
||||
"Copy secret key"
|
||||
}
|
||||
})
|
||||
.primary()
|
||||
.small()
|
||||
.on_click(cx.listener(move |this, _ev, _window, cx| {
|
||||
this.copy_secret(cx);
|
||||
})),
|
||||
Clipboard::new("copy-secret")
|
||||
.accessibility_label("Copy secret key")
|
||||
.value_fn({
|
||||
let nsec_input = self.nsec_input.clone();
|
||||
move |_, cx| nsec_input.read(cx).value()
|
||||
}),
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
@@ -340,7 +340,7 @@ impl Sidebar {
|
||||
)
|
||||
.child(
|
||||
div()
|
||||
.text_sm()
|
||||
.text_xs()
|
||||
.text_color(cx.theme().sidebar_foreground)
|
||||
.child(label),
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user