commit 475314da75fada4f38dc13c1c73f8175e5be34ad
parent 40c5dbf4181c3f29430d3f3536ddfe530a038ff9
Author: William Casarin <jb55@jb55.com>
Date: Fri, 20 Dec 2024 13:54:20 -0800
columns: navigate back when switching account
Fixes: https://github.com/damus-io/notedeck/issues/600
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
5 files changed, 45 insertions(+), 15 deletions(-)
diff --git 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<usize>,
+
+ /// The account index to switch to
+ pub switch_to: usize,
+}
+
+impl SwitchAccountAction {
+ pub fn new(source: Option<usize>, 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<usize> = 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
@@ -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
@@ -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
@@ -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
@@ -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);
}
}
}