notedeck

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

commit e8d240df42bd6fa344ae1c358c6f5ff6f54b9f0e
parent 0ea1a92ea7478a32bc2a51f55fa050c08d4d79da
Author: William Casarin <jb55@jb55.com>
Date:   Fri,  6 Jun 2025 15:40:04 -0700

toolbar: process actions

Signed-off-by: William Casarin <jb55@jb55.com>

Diffstat:
Mcrates/notedeck_chrome/src/chrome.rs | 63+++++++++++++++++++++++++++++++++++++++++++++++++++++----------
Mcrates/notedeck_columns/src/app.rs | 13++++++++++---
Mcrates/notedeck_columns/src/column.rs | 31++++++++++++++++++++++++++++++-
Mcrates/notedeck_columns/src/decks.rs | 5++---
4 files changed, 95 insertions(+), 17 deletions(-)

diff --git a/crates/notedeck_chrome/src/chrome.rs b/crates/notedeck_chrome/src/chrome.rs @@ -9,7 +9,8 @@ use notedeck::{ profile::get_profile_url, App, AppAction, AppContext, NotedeckTextStyle, UserAccount, WalletType, }; -use notedeck_columns::Damus; +use notedeck_columns::{timeline::kind::ListKind, timeline::TimelineKind, Damus}; + use notedeck_dave::{Dave, DaveAvatar}; use notedeck_ui::{AnimationHelper, ProfilePic}; @@ -36,6 +37,7 @@ impl Default for Chrome { /// When you click the toolbar button, these actions /// are returned +#[derive(Debug, Eq, PartialEq)] pub enum ToolbarAction { Notifications, Dave, @@ -52,12 +54,23 @@ pub enum ChromePanelAction { } impl ChromePanelAction { + fn columns_switch(ctx: &AppContext, chrome: &mut Chrome, kind: &TimelineKind) { + chrome.switch_to_columns(); + + if let Some(active_columns) = chrome + .get_columns() + .and_then(|cols| cols.decks_cache.active_columns_mut(ctx.accounts)) + { + active_columns.select_by_kind(kind) + } + } + fn columns_navigate(ctx: &AppContext, chrome: &mut Chrome, route: notedeck_columns::Route) { chrome.switch_to_columns(); if let Some(c) = chrome .get_columns() - .and_then(|columns| columns.decks_cache.first_column_mut(ctx.accounts)) + .and_then(|columns| columns.decks_cache.selected_column_mut(ctx.accounts)) { if c.router().routes().iter().any(|r| r == &route) { // return if we are already routing to accounts @@ -78,9 +91,33 @@ impl ChromePanelAction { ctx.theme.save(*theme); } - Self::Toolbar(_toolbar_action) => { - tracing::info!("toolbar action"); - } + Self::Toolbar(toolbar_action) => match toolbar_action { + ToolbarAction::Dave => chrome.switch_to_dave(), + + ToolbarAction::Home => { + if let Some(pubkey) = ctx + .accounts + .get_selected_account() + .map(|acc| acc.key.pubkey) + { + Self::columns_switch( + ctx, + chrome, + &TimelineKind::List(ListKind::Contact(pubkey)), + ); + } + } + + ToolbarAction::Notifications => { + if let Some(pubkey) = ctx + .accounts + .get_selected_account() + .map(|acc| acc.key.pubkey) + { + Self::columns_switch(ctx, chrome, &TimelineKind::Notifications(pubkey)); + } + } + }, Self::Support => { Self::columns_navigate(ctx, chrome, notedeck_columns::Route::Support); @@ -138,6 +175,14 @@ impl Chrome { None } + fn switch_to_dave(&mut self) { + for (i, app) in self.apps.iter().enumerate() { + if let NotedeckApp::Dave(_) = app { + self.active = i as i32; + } + } + } + fn switch_to_columns(&mut self) { for (i, app) in self.apps.iter().enumerate() { if let NotedeckApp::Columns(_) = app { @@ -282,10 +327,8 @@ impl Chrome { action = Some(ToolbarAction::Dave); } } - } else if index == 2 { - if notifications_button(ui).clicked() { - action = Some(ToolbarAction::Notifications); - } + } else if index == 2 && notifications_button(ui).clicked() { + action = Some(ToolbarAction::Notifications); } action @@ -350,7 +393,7 @@ impl Chrome { let rect = dave_sidebar_rect(ui); let dave_resp = dave_button(dave.avatar_mut(), ui, rect); if dave_resp.clicked() { - self.active = 1; + self.switch_to_dave(); } else if dave_resp.hovered() { notedeck_ui::show_pointer(ui); } diff --git a/crates/notedeck_columns/src/app.rs b/crates/notedeck_columns/src/app.rs @@ -534,9 +534,16 @@ fn render_damus_mobile( let mut rect = ui.available_rect_before_wrap(); let mut app_action: Option<AppAction> = None; + let active_col = app.columns_mut(app_ctx.accounts).selected as usize; if !app.columns(app_ctx.accounts).columns().is_empty() { - let r = nav::render_nav(0, ui.available_rect_before_wrap(), app, app_ctx, ui) - .process_render_nav_response(app, app_ctx, ui); + let r = nav::render_nav( + active_col, + ui.available_rect_before_wrap(), + app, + app_ctx, + ui, + ) + .process_render_nav_response(app, app_ctx, ui); if let Some(r) = &r { match r { ProcessNavResult::SwitchOccurred => { @@ -563,7 +570,7 @@ fn render_damus_mobile( .clicked() && !app.columns(app_ctx.accounts).columns().is_empty() { - let router = app.columns_mut(app_ctx.accounts).columns_mut()[0].router_mut(); + let router = app.columns_mut(app_ctx.accounts).selected().router_mut(); if router.top() == &Route::ComposeNote { router.go_back(); } else { diff --git a/crates/notedeck_columns/src/column.rs b/crates/notedeck_columns/src/column.rs @@ -39,7 +39,7 @@ pub struct Columns { columns: Vec<Column>, /// The selected column for key navigation - selected: i32, + pub selected: i32, } impl Columns { @@ -47,6 +47,35 @@ impl Columns { Columns::default() } + /// Choose which column is selected. If in narrow mode, this + /// decides which column to render in the main view + pub fn select_column(&mut self, index: i32) { + let len = self.columns.len(); + + if index < (len as i32) { + self.selected = index; + } + } + + /// Select the column based on the timeline kind. + /// + /// TODO: add timeline if missing? + pub fn select_by_kind(&mut self, kind: &TimelineKind) { + for (i, col) in self.columns.iter().enumerate() { + for route in col.router().routes() { + if let Some(timeline) = route.timeline_id() { + if timeline == kind { + tracing::info!("selecting {kind:?} column"); + self.select_column(i as i32); + return; + } + } + } + } + + tracing::error!("failed to select {kind:?} column"); + } + pub fn add_new_timeline_column( &mut self, timeline_cache: &mut TimelineCache, diff --git a/crates/notedeck_columns/src/decks.rs b/crates/notedeck_columns/src/decks.rs @@ -37,9 +37,8 @@ impl Default for DecksCache { impl DecksCache { /// Gets the first column in the currently active user's active deck - pub fn first_column_mut(&mut self, accounts: &notedeck::Accounts) -> Option<&mut Column> { - self.active_columns_mut(accounts) - .and_then(|ad| ad.columns_mut().first_mut()) + pub fn selected_column_mut(&mut self, accounts: &notedeck::Accounts) -> Option<&mut Column> { + self.active_columns_mut(accounts).map(|ad| ad.selected()) } /// Gets the active columns