migrate to gpui-component

This commit is contained in:
2026-06-02 18:15:54 +07:00
parent 5d4c8634ef
commit bac04ab4da
116 changed files with 1165 additions and 24445 deletions

View File

@@ -1,17 +1,17 @@
use std::time::Duration;
use anyhow::Error;
use common::CoopIcon;
use gpui::{
AnyElement, App, AppContext, ClipboardItem, Context, Entity, EventEmitter, FocusHandle,
Focusable, IntoElement, ParentElement, Render, SharedString, Styled, Task, Window, div,
App, AppContext, ClipboardItem, Context, Entity, EventEmitter, FocusHandle, Focusable,
IntoElement, ParentElement, Render, SharedString, Styled, Task, Window, div,
};
use gpui_component::button::{Button, ButtonVariants};
use gpui_component::dock::{Panel, PanelEvent};
use gpui_component::input::{Input, InputState};
use gpui_component::{ActiveTheme, Sizable, StyledExt, v_flex};
use nostr_sdk::prelude::*;
use state::KEYRING;
use theme::ActiveTheme;
use ui::button::{Button, ButtonVariants};
use ui::dock::{Panel, PanelEvent};
use ui::input::{InputState, TextInput};
use ui::{IconName, Sizable, StyledExt, divider, v_flex};
const MSG: &str = "Store your account keys in a safe location. \
You can restore your account or move to another client anytime you want.";
@@ -22,7 +22,6 @@ pub fn init(window: &mut Window, cx: &mut App) -> Entity<BackupPanel> {
#[derive(Debug)]
pub struct BackupPanel {
name: SharedString,
focus_handle: FocusHandle,
/// Public key input
@@ -40,8 +39,8 @@ pub struct BackupPanel {
impl BackupPanel {
pub fn new(window: &mut Window, cx: &mut Context<Self>) -> Self {
let npub_input = cx.new(|cx| InputState::new(window, cx).disabled(true));
let nsec_input = cx.new(|cx| InputState::new(window, cx).disabled(true).masked(true));
let npub_input = cx.new(|cx| InputState::new(window, cx));
let nsec_input = cx.new(|cx| InputState::new(window, cx).masked(true));
// Run at the end of current cycle
cx.defer_in(window, |this, window, cx| {
@@ -49,7 +48,6 @@ impl BackupPanel {
});
Self {
name: "Backup".into(),
focus_handle: cx.focus_handle(),
npub_input,
nsec_input,
@@ -108,12 +106,8 @@ impl BackupPanel {
}
impl Panel for BackupPanel {
fn panel_id(&self) -> SharedString {
self.name.clone()
}
fn title(&self, _cx: &App) -> AnyElement {
self.name.clone().into_any_element()
fn panel_name(&self) -> &'static str {
"Backup"
}
}
@@ -134,10 +128,10 @@ impl Render for BackupPanel {
.child(
div()
.text_xs()
.text_color(cx.theme().text_muted)
.text_color(cx.theme().muted_foreground)
.child(SharedString::from(MSG)),
)
.child(divider(cx))
.child(div().h_1().w_full().bg(cx.theme().border))
.child(
v_flex()
.gap_2()
@@ -152,11 +146,11 @@ impl Render for BackupPanel {
div()
.text_xs()
.font_semibold()
.text_color(cx.theme().text_muted)
.text_color(cx.theme().muted_foreground)
.child(SharedString::from("Public Key:")),
)
.child(
TextInput::new(&self.npub_input)
Input::new(&self.npub_input)
.small()
.bordered(false)
.disabled(true),
@@ -170,11 +164,11 @@ impl Render for BackupPanel {
div()
.text_xs()
.font_semibold()
.text_color(cx.theme().text_muted)
.text_color(cx.theme().muted_foreground)
.child(SharedString::from("Secret Key:")),
)
.child(
TextInput::new(&self.nsec_input)
Input::new(&self.nsec_input)
.small()
.bordered(false)
.disabled(true),
@@ -182,7 +176,7 @@ impl Render for BackupPanel {
)
.child(
Button::new("copy")
.icon(IconName::Copy)
.icon(CoopIcon::Copy)
.label({
if self.copied {
"Copied"