columns: navigate back when switching account
Fixes: https://github.com/damus-io/notedeck/issues/600 Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user