notedeck

One damus client to rule them all
git clone git://jb55.com/notedeck
Log | Files | Refs | README | LICENSE

commit f452a9010b8ec03bcd045781b46d76f59856a87f
parent 08a720b860f36396a1e721e960fe2c9d7823e004
Author: kernelkind <kernelkind@gmail.com>
Date:   Thu, 22 May 2025 19:31:41 -0400

nav: move action processing to own method

Signed-off-by: kernelkind <kernelkind@gmail.com>

Diffstat:
Mcrates/notedeck_columns/src/nav.rs | 161++++++++++++++++++++++++++++++++++++++++++-------------------------------------
1 file changed, 85 insertions(+), 76 deletions(-)

diff --git a/crates/notedeck_columns/src/nav.rs b/crates/notedeck_columns/src/nav.rs @@ -147,83 +147,8 @@ impl RenderNavResponse { if let Some(action) = self.response.response.or(self.response.title_response) { // start returning when we're finished posting - match action { - RenderNavAction::Back => { - app.columns_mut(ctx.accounts) - .column_mut(col) - .router_mut() - .go_back(); - } - - RenderNavAction::RemoveColumn => { - let kinds_to_pop = app.columns_mut(ctx.accounts).delete_column(col); - - for kind in &kinds_to_pop { - if let Err(err) = app.timeline_cache.pop(kind, ctx.ndb, ctx.pool) { - error!("error popping timeline: {err}"); - } - } - - switching_occured = true; - } - - RenderNavAction::PostAction(new_post_action) => { - let txn = Transaction::new(ctx.ndb).expect("txn"); - match new_post_action.execute(ctx.ndb, &txn, ctx.pool, &mut app.drafts) { - Err(err) => tracing::error!("Error executing post action: {err}"), - Ok(_) => tracing::debug!("Post action executed"), - } - get_active_columns_mut(ctx.accounts, &mut app.decks_cache) - .column_mut(col) - .router_mut() - .go_back(); - } - - RenderNavAction::NoteAction(note_action) => { - let txn = Transaction::new(ctx.ndb).expect("txn"); - - crate::actionbar::execute_and_process_note_action( - note_action, - ctx.ndb, - get_active_columns_mut(ctx.accounts, &mut app.decks_cache), - col, - &mut app.timeline_cache, - ctx.note_cache, - ctx.pool, - &txn, - ctx.unknown_ids, - ctx.accounts, - ctx.global_wallet, - ctx.zaps, - ctx.img_cache, - ui, - ); - } - RenderNavAction::SwitchingAction(switching_action) => { - switching_occured = switching_action.process( - &mut app.timeline_cache, - &mut app.decks_cache, - ctx, - ); - } - RenderNavAction::ProfileAction(profile_action) => { - profile_action.process( - &mut app.view_state.pubkey_to_profile_state, - ctx.ndb, - ctx.pool, - get_active_columns_mut(ctx.accounts, &mut app.decks_cache) - .column_mut(col) - .router_mut(), - ); - } - RenderNavAction::WalletAction(wallet_action) => { - let router = get_active_columns_mut(ctx.accounts, &mut app.decks_cache) - .column_mut(col) - .router_mut(); - wallet_action.process(ctx.accounts, ctx.global_wallet, router) - } - } + switching_occured = process_render_nav_action(app, ctx, ui, col, action); } if let Some(action) = self.response.action { @@ -264,6 +189,90 @@ impl RenderNavResponse { } } +fn process_render_nav_action( + app: &mut Damus, + ctx: &mut AppContext<'_>, + ui: &mut egui::Ui, + col: usize, + action: RenderNavAction, +) -> bool { + match action { + RenderNavAction::Back => { + app.columns_mut(ctx.accounts) + .column_mut(col) + .router_mut() + .go_back(); + } + + RenderNavAction::RemoveColumn => { + let kinds_to_pop = app.columns_mut(ctx.accounts).delete_column(col); + + for kind in &kinds_to_pop { + if let Err(err) = app.timeline_cache.pop(kind, ctx.ndb, ctx.pool) { + error!("error popping timeline: {err}"); + } + } + + return true; + } + + RenderNavAction::PostAction(new_post_action) => { + let txn = Transaction::new(ctx.ndb).expect("txn"); + match new_post_action.execute(ctx.ndb, &txn, ctx.pool, &mut app.drafts) { + Err(err) => tracing::error!("Error executing post action: {err}"), + Ok(_) => tracing::debug!("Post action executed"), + } + get_active_columns_mut(ctx.accounts, &mut app.decks_cache) + .column_mut(col) + .router_mut() + .go_back(); + } + + RenderNavAction::NoteAction(note_action) => { + let txn = Transaction::new(ctx.ndb).expect("txn"); + + crate::actionbar::execute_and_process_note_action( + note_action, + ctx.ndb, + get_active_columns_mut(ctx.accounts, &mut app.decks_cache), + col, + &mut app.timeline_cache, + ctx.note_cache, + ctx.pool, + &txn, + ctx.unknown_ids, + ctx.accounts, + ctx.global_wallet, + ctx.zaps, + ctx.img_cache, + ui, + ); + } + + RenderNavAction::SwitchingAction(switching_action) => { + return switching_action.process(&mut app.timeline_cache, &mut app.decks_cache, ctx); + } + RenderNavAction::ProfileAction(profile_action) => { + profile_action.process( + &mut app.view_state.pubkey_to_profile_state, + ctx.ndb, + ctx.pool, + get_active_columns_mut(ctx.accounts, &mut app.decks_cache) + .column_mut(col) + .router_mut(), + ); + } + RenderNavAction::WalletAction(wallet_action) => { + let router = get_active_columns_mut(ctx.accounts, &mut app.decks_cache) + .column_mut(col) + .router_mut(); + wallet_action.process(ctx.accounts, ctx.global_wallet, router) + } + } + + false +} + fn render_nav_body( ui: &mut egui::Ui, app: &mut Damus,