notedeck

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

commit 224d46bc4fb86bf48cfd4e7cc4889336d350e408
parent fb4b682919006ccacdd7b3371ba9a9351e931e46
Author: kernelkind <kernelkind@gmail.com>
Date:   Thu, 18 Dec 2025 16:53:35 -0500

feat(router): move route_to_replaced to Router & add other impl

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

Diffstat:
Mcrates/notedeck/src/lib.rs | 2+-
Mcrates/notedeck/src/route.rs | 40++++++++++++++++++++++++++++++++++++++++
Mcrates/notedeck_columns/src/route.rs | 22+++++++---------------
3 files changed, 48 insertions(+), 16 deletions(-)

diff --git a/crates/notedeck/src/lib.rs b/crates/notedeck/src/lib.rs @@ -81,7 +81,7 @@ pub use profile::*; pub use relay_debug::RelayDebugView; pub use relayspec::RelaySpec; pub use result::Result; -pub use route::{DrawerRouter, Router}; +pub use route::{DrawerRouter, ReplacementType, Router}; pub use storage::{AccountStorage, DataPath, DataPathType, Directory}; pub use style::NotedeckTextStyle; pub use theme::ColorTheme; diff --git a/crates/notedeck/src/route.rs b/crates/notedeck/src/route.rs @@ -35,6 +35,13 @@ pub struct Router<R: Clone> { pub routes: Vec<R>, pub returning: bool, pub navigating: bool, + replacing: Option<ReplacementType>, +} + +#[derive(Clone, Debug)] +pub enum ReplacementType { + Single, + All, } impl<R: Clone> Router<R> { @@ -44,10 +51,12 @@ impl<R: Clone> Router<R> { } let returning = false; let navigating = false; + let replacing = None; Self { routes, returning, + replacing, navigating, } } @@ -57,6 +66,12 @@ impl<R: Clone> Router<R> { self.routes.push(route); } + // Route to R. Then when it is successfully placed, should call `remove_previous_routes` to remove all previous routes + pub fn route_to_replaced(&mut self, route: R, replacement_type: ReplacementType) { + self.replacing = Some(replacement_type); + self.route_to(route); + } + /// Go back, start the returning process pub fn go_back(&mut self) -> Option<R> { if self.returning || self.routes.len() == 1 { @@ -99,4 +114,29 @@ impl<R: Clone> Router<R> { pub fn is_empty(&self) -> bool { self.routes.is_empty() } + + pub fn is_replacing(&self) -> bool { + self.replacing.is_some() + } + + pub fn complete_replacement(&mut self) { + let num_routes = self.len(); + + self.returning = false; + let Some(replacement) = self.replacing.take() else { + return; + }; + if num_routes < 2 { + return; + } + + match replacement { + ReplacementType::Single => { + self.routes.remove(num_routes - 2); + } + ReplacementType::All => { + self.routes.drain(..num_routes - 1); + } + } + } } diff --git a/crates/notedeck_columns/src/route.rs b/crates/notedeck_columns/src/route.rs @@ -1,6 +1,8 @@ use egui_nav::Percent; use enostr::{NoteId, Pubkey}; -use notedeck::{tr, Localization, NoteZapTargetOwned, RootNoteIdBuf, Router, WalletType}; +use notedeck::{ + tr, Localization, NoteZapTargetOwned, ReplacementType, RootNoteIdBuf, Router, WalletType, +}; use std::ops::Range; use crate::{ @@ -420,7 +422,6 @@ impl Route { #[derive(Clone, Debug)] pub struct ColumnsRouter<R: Clone> { router_internal: Router<R>, - replacing: bool, forward_stack: Vec<R>, // An overlay captures a range of routes where only one will persist when going back, the most recent added @@ -432,11 +433,9 @@ impl<R: Clone> ColumnsRouter<R> { if routes.is_empty() { panic!("routes can't be empty") } - let replacing = false; let router_internal = Router::new(routes); ColumnsRouter { router_internal, - replacing, forward_stack: Vec::new(), overlay_ranges: Vec::new(), } @@ -459,8 +458,8 @@ impl<R: Clone> ColumnsRouter<R> { // Route to R. Then when it is successfully placed, should call `remove_previous_routes` to remove all previous routes pub fn route_to_replaced(&mut self, route: R) { - self.replacing = true; - self.router_internal.route_to(route); + self.router_internal + .route_to_replaced(route, ReplacementType::All); } /// Go back, start the returning process @@ -520,14 +519,7 @@ impl<R: Clone> ColumnsRouter<R> { } pub fn remove_previous_routes(&mut self) { - let num_routes = self.router_internal.len(); - if num_routes <= 1 { - return; - } - - self.router_internal.returning = false; - self.replacing = false; - self.router_internal.routes.drain(..num_routes - 1); + self.router_internal.complete_replacement(); } /// Removes all routes in the overlay besides the last @@ -547,7 +539,7 @@ impl<R: Clone> ColumnsRouter<R> { } pub fn is_replacing(&self) -> bool { - self.replacing + self.router_internal.is_replacing() } fn set_overlaying(&mut self) {