commit d4082eb818613d348da4771ea18c96fc218bb1d4
parent 0b8a4fdf559ced0e21e9856df2f067d82c29c9f9
Author: kernelkind <kernelkind@gmail.com>
Date: Thu, 17 Jul 2025 20:31:36 -0400
bugfix: properly sub to new selected acc after removal of selected
Signed-off-by: kernelkind <kernelkind@gmail.com>
Diffstat:
3 files changed, 42 insertions(+), 11 deletions(-)
diff --git a/crates/notedeck/src/account/accounts.rs b/crates/notedeck/src/account/accounts.rs
@@ -97,16 +97,31 @@ impl Accounts {
}
}
- pub fn remove_account(&mut self, pk: &Pubkey) {
- let Some(removed) = self.cache.remove(pk) else {
- return;
+ pub fn remove_account(
+ &mut self,
+ pk: &Pubkey,
+ ndb: &mut Ndb,
+ pool: &mut RelayPool,
+ ctx: &egui::Context,
+ ) -> bool {
+ let Some(resp) = self.cache.remove(pk) else {
+ return false;
};
- if let Some(key_store) = &self.storage_writer {
- if let Err(e) = key_store.remove_key(&removed.key) {
- tracing::error!("Could not remove account {pk}: {e}");
+ if pk != self.cache.fallback() {
+ if let Some(key_store) = &self.storage_writer {
+ if let Err(e) = key_store.remove_key(&resp.deleted) {
+ tracing::error!("Could not remove account {pk}: {e}");
+ }
}
}
+
+ if let Some(swap_to) = resp.swap_to {
+ let txn = Transaction::new(ndb).expect("txn");
+ self.select_account_internal(&swap_to, ndb, &txn, pool, ctx);
+ }
+
+ true
}
pub fn contains_full_kp(&self, pubkey: &enostr::Pubkey) -> bool {
diff --git a/crates/notedeck/src/account/cache.rs b/crates/notedeck/src/account/cache.rs
@@ -50,20 +50,20 @@ impl AccountCache {
self.accounts.entry(pk).insert(account)
}
- pub(super) fn remove(&mut self, pk: &Pubkey) -> Option<UserAccount> {
+ pub(super) fn remove(&mut self, pk: &Pubkey) -> Option<AccountDeletionResponse> {
if *pk == self.fallback && self.accounts.len() == 1 {
// no point in removing it since it'll just get re-added anyway
return None;
}
- let removed = self.accounts.remove(pk);
+ let removed = self.accounts.remove(pk)?;
if self.accounts.is_empty() {
self.accounts
.insert(self.fallback, self.fallback_account.clone());
}
- if removed.is_some() && self.selected == *pk {
+ if self.selected == *pk {
// TODO(kernelkind): choose next better
let (next, _) = self
.accounts
@@ -71,9 +71,17 @@ impl AccountCache {
.next()
.expect("accounts can never be empty");
self.selected = *next;
+
+ return Some(AccountDeletionResponse {
+ deleted: removed.key,
+ swap_to: Some(*next),
+ });
}
- removed
+ Some(AccountDeletionResponse {
+ deleted: removed.key,
+ swap_to: None,
+ })
}
/// guarenteed that all selected exist in accounts
@@ -111,3 +119,8 @@ impl<'a> IntoIterator for &'a AccountCache {
self.accounts.iter()
}
}
+
+pub struct AccountDeletionResponse {
+ pub deleted: enostr::Keypair,
+ pub swap_to: Option<Pubkey>,
+}
diff --git a/crates/notedeck_columns/src/nav.rs b/crates/notedeck_columns/src/nav.rs
@@ -94,7 +94,10 @@ impl SwitchingAction {
.router_mut()
.go_back();
}
- AccountsAction::Remove(to_remove) => ctx.accounts.remove_account(to_remove),
+ AccountsAction::Remove(to_remove) => {
+ ctx.accounts
+ .remove_account(to_remove, ctx.ndb, ctx.pool, ui_ctx);
+ }
},
SwitchingAction::Columns(columns_action) => match *columns_action {
ColumnsAction::Remove(index) => {