diff --git a/crates/notedeck/src/accounts.rs b/crates/notedeck/src/accounts.rs index 03f125d..354be84 100644 --- a/crates/notedeck/src/accounts.rs +++ b/crates/notedeck/src/accounts.rs @@ -13,9 +13,24 @@ use uuid::Uuid; // TODO: remove this use std::sync::Arc; +#[derive(Debug, Clone)] +pub struct SwitchAccountAction { + /// Some index representing the source of the action + pub source: Option, + + /// The account index to switch to + pub switch_to: usize, +} + +impl SwitchAccountAction { + pub fn new(source: Option, switch_to: usize) -> Self { + SwitchAccountAction { source, switch_to } + } +} + #[derive(Debug)] pub enum AccountsAction { - Switch(usize), + Switch(SwitchAccountAction), Remove(usize), } @@ -338,8 +353,12 @@ impl Accounts { self.accounts.len() - 1 }; + let source: Option = None; AddAccountAction { - accounts_action: Some(AccountsAction::Switch(switch_to_index)), + accounts_action: Some(AccountsAction::Switch(SwitchAccountAction::new( + source, + switch_to_index, + ))), unk_id_action: SingleUnkIdAction::pubkey(pubkey), } } diff --git a/crates/notedeck/src/lib.rs b/crates/notedeck/src/lib.rs index 50ad2c7..842bba8 100644 --- a/crates/notedeck/src/lib.rs +++ b/crates/notedeck/src/lib.rs @@ -20,7 +20,7 @@ pub mod ui; mod unknowns; mod user_account; -pub use accounts::{AccountData, Accounts, AccountsAction, AddAccountAction}; +pub use accounts::{AccountData, Accounts, AccountsAction, AddAccountAction, SwitchAccountAction}; pub use app::App; pub use args::Args; pub use context::AppContext; diff --git a/crates/notedeck_columns/src/accounts/mod.rs b/crates/notedeck_columns/src/accounts/mod.rs index 1c93837..4eb1d3e 100644 --- a/crates/notedeck_columns/src/accounts/mod.rs +++ b/crates/notedeck_columns/src/accounts/mod.rs @@ -1,7 +1,9 @@ use enostr::FullKeypair; use nostrdb::Ndb; -use notedeck::{Accounts, AccountsAction, AddAccountAction, ImageCache, SingleUnkIdAction}; +use notedeck::{ + Accounts, AccountsAction, AddAccountAction, ImageCache, SingleUnkIdAction, SwitchAccountAction, +}; use crate::app::get_active_columns_mut; use crate::decks::DecksCache; @@ -87,7 +89,7 @@ pub fn process_accounts_view_response( selection = Some(acc_sel); } AccountsViewResponse::SelectAccount(index) => { - let acc_sel = AccountsAction::Switch(index); + let acc_sel = AccountsAction::Switch(SwitchAccountAction::new(Some(col), index)); info!("account selection: {:?}", acc_sel); selection = Some(acc_sel); } diff --git a/crates/notedeck_columns/src/app.rs b/crates/notedeck_columns/src/app.rs index cef57f9..99d4048 100644 --- a/crates/notedeck_columns/src/app.rs +++ b/crates/notedeck_columns/src/app.rs @@ -620,7 +620,7 @@ fn timelines_view(ui: &mut egui::Ui, sizes: Size, app: &mut Damus, ctx: &mut App let mut save_cols = false; if let Some(action) = side_panel_action { - save_cols = save_cols || action.process(app, ctx); + save_cols = save_cols || action.process(&mut app.decks_cache, ctx); } let num_cols = app.columns(ctx.accounts).num_columns(); diff --git a/crates/notedeck_columns/src/nav.rs b/crates/notedeck_columns/src/nav.rs index c6afc73..a9746c7 100644 --- a/crates/notedeck_columns/src/nav.rs +++ b/crates/notedeck_columns/src/nav.rs @@ -4,7 +4,7 @@ use crate::{ app::{get_active_columns, get_active_columns_mut, get_decks_mut}, column::ColumnsAction, deck_state::DeckState, - decks::{Deck, DecksAction}, + decks::{Deck, DecksAction, DecksCache}, notes_holder::NotesHolder, profile::Profile, relay_pool_manager::RelayPoolManager, @@ -50,23 +50,32 @@ pub enum SwitchingAction { impl SwitchingAction { /// process the action, and return whether switching occured - pub fn process(&self, app: &mut Damus, ctx: &mut AppContext<'_>) -> bool { + pub fn process(&self, decks_cache: &mut DecksCache, ctx: &mut AppContext<'_>) -> bool { match &self { - SwitchingAction::Accounts(account_action) => match *account_action { - AccountsAction::Switch(index) => ctx.accounts.select_account(index), - AccountsAction::Remove(index) => ctx.accounts.remove_account(index), + SwitchingAction::Accounts(account_action) => match account_action { + AccountsAction::Switch(switch_action) => { + ctx.accounts.select_account(switch_action.switch_to); + // pop nav after switch + if let Some(src) = switch_action.source { + get_active_columns_mut(ctx.accounts, decks_cache) + .column_mut(src) + .router_mut() + .go_back(); + } + } + AccountsAction::Remove(index) => ctx.accounts.remove_account(*index), }, SwitchingAction::Columns(columns_action) => match *columns_action { ColumnsAction::Remove(index) => { - get_active_columns_mut(ctx.accounts, &mut app.decks_cache).delete_column(index) + get_active_columns_mut(ctx.accounts, decks_cache).delete_column(index) } }, SwitchingAction::Decks(decks_action) => match *decks_action { DecksAction::Switch(index) => { - get_decks_mut(ctx.accounts, &mut app.decks_cache).set_active(index) + get_decks_mut(ctx.accounts, decks_cache).set_active(index) } DecksAction::Removing(index) => { - get_decks_mut(ctx.accounts, &mut app.decks_cache).remove_deck(index) + get_decks_mut(ctx.accounts, decks_cache).remove_deck(index) } }, } @@ -157,7 +166,7 @@ impl RenderNavResponse { } RenderNavAction::SwitchingAction(switching_action) => { - switching_occured = switching_action.process(app, ctx); + switching_occured = switching_action.process(&mut app.decks_cache, ctx); } } }