mirror of
https://github.com/aljazceru/notedeck.git
synced 2025-12-18 17:14:21 +01:00
bugfix: properly sub to new selected acc after removal of selected
Signed-off-by: kernelkind <kernelkind@gmail.com>
This commit is contained in:
@@ -97,16 +97,31 @@ impl Accounts {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_account(&mut self, pk: &Pubkey) {
|
pub fn remove_account(
|
||||||
let Some(removed) = self.cache.remove(pk) else {
|
&mut self,
|
||||||
return;
|
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 pk != self.cache.fallback() {
|
||||||
if let Err(e) = key_store.remove_key(&removed.key) {
|
if let Some(key_store) = &self.storage_writer {
|
||||||
tracing::error!("Could not remove account {pk}: {e}");
|
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 {
|
pub fn contains_full_kp(&self, pubkey: &enostr::Pubkey) -> bool {
|
||||||
|
|||||||
@@ -50,20 +50,20 @@ impl AccountCache {
|
|||||||
self.accounts.entry(pk).insert(account)
|
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 {
|
if *pk == self.fallback && self.accounts.len() == 1 {
|
||||||
// no point in removing it since it'll just get re-added anyway
|
// no point in removing it since it'll just get re-added anyway
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let removed = self.accounts.remove(pk);
|
let removed = self.accounts.remove(pk)?;
|
||||||
|
|
||||||
if self.accounts.is_empty() {
|
if self.accounts.is_empty() {
|
||||||
self.accounts
|
self.accounts
|
||||||
.insert(self.fallback, self.fallback_account.clone());
|
.insert(self.fallback, self.fallback_account.clone());
|
||||||
}
|
}
|
||||||
|
|
||||||
if removed.is_some() && self.selected == *pk {
|
if self.selected == *pk {
|
||||||
// TODO(kernelkind): choose next better
|
// TODO(kernelkind): choose next better
|
||||||
let (next, _) = self
|
let (next, _) = self
|
||||||
.accounts
|
.accounts
|
||||||
@@ -71,9 +71,17 @@ impl AccountCache {
|
|||||||
.next()
|
.next()
|
||||||
.expect("accounts can never be empty");
|
.expect("accounts can never be empty");
|
||||||
self.selected = *next;
|
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
|
/// guarenteed that all selected exist in accounts
|
||||||
@@ -111,3 +119,8 @@ impl<'a> IntoIterator for &'a AccountCache {
|
|||||||
self.accounts.iter()
|
self.accounts.iter()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub struct AccountDeletionResponse {
|
||||||
|
pub deleted: enostr::Keypair,
|
||||||
|
pub swap_to: Option<Pubkey>,
|
||||||
|
}
|
||||||
|
|||||||
@@ -94,7 +94,10 @@ impl SwitchingAction {
|
|||||||
.router_mut()
|
.router_mut()
|
||||||
.go_back();
|
.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 {
|
SwitchingAction::Columns(columns_action) => match *columns_action {
|
||||||
ColumnsAction::Remove(index) => {
|
ColumnsAction::Remove(index) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user