diff --git a/crates/coop/src/dialogs/accounts.rs b/crates/coop/src/dialogs/accounts.rs index 460f288..7b84b57 100644 --- a/crates/coop/src/dialogs/accounts.rs +++ b/crates/coop/src/dialogs/accounts.rs @@ -82,6 +82,14 @@ impl AccountSelector { })); } + fn remove(&mut self, public_key: PublicKey, cx: &mut Context) { + let nostr = NostrRegistry::global(cx); + + nostr.update(cx, |this, cx| { + this.remove_signer(&public_key, cx); + }); + } + fn open_import(&mut self, window: &mut Window, cx: &mut Context) { let import = cx.new(|cx| ImportKey::new(window, cx)); @@ -138,13 +146,36 @@ impl Render for AccountSelector { .group("") .px_2() .h_10() - .gap_2() + .justify_between() .w_full() .rounded(cx.theme().radius) .bg(cx.theme().ghost_element_background) .hover(|this| this.bg(cx.theme().ghost_element_hover)) - .child(Avatar::new(profile.avatar()).small()) - .child(div().text_sm().child(profile.name())) + .child( + h_flex() + .gap_2() + .child(Avatar::new(profile.avatar()).small()) + .child(div().text_sm().child(profile.name())), + ) + .child( + h_flex() + .gap_1() + .invisible() + .group_hover("", |this| this.visible()) + .child( + Button::new(format!("del-{ix}")) + .icon(IconName::Close) + .ghost() + .small() + .on_click(cx.listener({ + let public_key = *public_key; + move |this, _ev, _window, cx| { + cx.stop_propagation(); + this.remove(public_key, cx); + } + })), + ), + ) .on_click(cx.listener({ let public_key = *public_key; move |this, _ev, window, cx| { diff --git a/crates/coop/src/workspace.rs b/crates/coop/src/workspace.rs index 43153d7..71cd1fe 100644 --- a/crates/coop/src/workspace.rs +++ b/crates/coop/src/workspace.rs @@ -458,8 +458,15 @@ impl Workspace { h_flex() .flex_shrink_0() - .justify_between() .gap_2() + .when_none(¤t_user, |this| { + this.child( + div() + .text_xs() + .text_color(cx.theme().text_muted) + .child(SharedString::from("Choose an account to continue...")), + ) + }) .when_some(current_user.as_ref(), |this, public_key| { let persons = PersonRegistry::global(cx); let profile = persons.read(cx).get(public_key, cx); diff --git a/crates/state/src/lib.rs b/crates/state/src/lib.rs index 3fd900e..02691af 100644 --- a/crates/state/src/lib.rs +++ b/crates/state/src/lib.rs @@ -466,6 +466,27 @@ impl NostrRegistry { })); } + /// Remove a signer from the keyring + pub fn remove_signer(&mut self, public_key: &PublicKey, cx: &mut Context) { + let public_key = public_key.to_owned(); + let npub = public_key.to_bech32().unwrap(); + let keys_dir = config_dir().join("keys"); + + self.tasks.push(cx.spawn(async move |this, cx| { + let key_path = keys_dir.join(format!("{}.npub", npub)); + smol::fs::remove_file(key_path).await?; + + this.update(cx, |this, cx| { + this.npubs().update(cx, |this, cx| { + this.retain(|k| k != &public_key); + cx.notify(); + }); + })?; + + Ok(()) + })); + } + /// Add a key signer to keyring pub fn add_key_signer(&mut self, keys: &Keys, cx: &mut Context) { let keys = keys.clone();