From ee0029268f1b16f26383b710e760abce3060c1c8 Mon Sep 17 00:00:00 2001 From: kernelkind Date: Fri, 6 Sep 2024 18:31:50 -0400 Subject: [PATCH] add RoutableWidgetState conception holds the routes for an arbitrary widget Signed-off-by: kernelkind --- src/app.rs | 11 +++++------ src/lib.rs | 1 + src/routable_widget_state.rs | 26 ++++++++++++++++++++++++++ src/route.rs | 29 +++++++++++++++++------------ 4 files changed, 49 insertions(+), 18 deletions(-) create mode 100644 src/routable_widget_state.rs diff --git a/src/app.rs b/src/app.rs index 5a4024a3..79457179 100644 --- a/src/app.rs +++ b/src/app.rs @@ -13,7 +13,8 @@ use crate::key_storage::KeyStorageType; use crate::note::NoteRef; use crate::notecache::{CachedNote, NoteCache}; use crate::relay_pool_manager::RelayPoolManager; -use crate::route::Route; +use crate::routable_widget_state::RoutableWidgetState; +use crate::route::{ManageAccountRoute, Route}; use crate::subscriptions::{SubKind, Subscriptions}; use crate::thread::{DecrementResult, Threads}; use crate::timeline::{Timeline, TimelineKind, TimelineSource, ViewFilter}; @@ -49,6 +50,7 @@ pub struct Damus { pub pool: RelayPool, pub columns: Columns, + pub account_management_view_state: RoutableWidgetState, pub ndb: Ndb, pub unknown_ids: UnknownIds, pub drafts: Drafts, @@ -697,6 +699,7 @@ impl Damus { accounts, frame_history: FrameHistory::default(), show_account_switcher: false, + account_management_view_state: RoutableWidgetState::default(), } } @@ -739,6 +742,7 @@ impl Damus { accounts: AccountManager::new(None, KeyStorageType::None), frame_history: FrameHistory::default(), show_account_switcher: false, + account_management_view_state: RoutableWidgetState::default(), } } @@ -949,11 +953,6 @@ fn render_nav(show_postbox: bool, col: usize, app: &mut Damus, ui: &mut egui::Ui None } - Route::ManageAccount => { - ui.label("account management view"); - None - } - Route::Relays => { let manager = RelayPoolManager::new(&mut app.pool); RelayView::new(manager).ui(ui); diff --git a/src/lib.rs b/src/lib.rs index e1151537..36897325 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -27,6 +27,7 @@ mod post; mod profile; pub mod relay_pool_manager; mod result; +mod routable_widget_state; mod route; mod subscriptions; mod test_data; diff --git a/src/routable_widget_state.rs b/src/routable_widget_state.rs new file mode 100644 index 00000000..4173367c --- /dev/null +++ b/src/routable_widget_state.rs @@ -0,0 +1,26 @@ +#[derive(Default)] +pub struct RoutableWidgetState { + routes: Vec, +} + +impl RoutableWidgetState { + pub fn route_to(&mut self, route: R) { + self.routes.push(route); + } + + pub fn clear(&mut self) { + self.routes.clear(); + } + + pub fn go_back(&mut self) { + self.routes.pop(); + } + + pub fn top(&self) -> Option { + self.routes.last().cloned() + } + + pub fn get_routes(&self) -> Vec { + self.routes.clone() + } +} diff --git a/src/route.rs b/src/route.rs index 5518452c..fe02e72e 100644 --- a/src/route.rs +++ b/src/route.rs @@ -1,23 +1,31 @@ -use egui::{Response, RichText}; +use egui::RichText; use enostr::NoteId; use std::fmt::{self}; +use strum_macros::Display; -use crate::{ui::AccountManagementView, Damus}; +use crate::ui::{ + account_login_view::AccountLoginResponse, account_management::AccountManagementViewResponse, +}; /// App routing. These describe different places you can go inside Notedeck. #[derive(Clone, Debug)] pub enum Route { Timeline(String), - ManageAccount, Thread(NoteId), Reply(NoteId), Relays, } +#[derive(Clone, Debug, Default, Display)] +pub enum ManageAccountRoute { + #[default] + AccountManagement, + AddAccount, +} + impl fmt::Display for Route { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { - Route::ManageAccount => write!(f, "Manage Account"), Route::Timeline(name) => write!(f, "{}", name), Route::Thread(_id) => write!(f, "Thread"), Route::Reply(_id) => write!(f, "Reply"), @@ -27,16 +35,8 @@ impl fmt::Display for Route { } impl Route { - pub fn show_global_popup(&self, app: &mut Damus, ui: &mut egui::Ui) -> Option { - match self { - Route::ManageAccount => AccountManagementView::ui(app, ui), - _ => None, - } - } - pub fn title(&self) -> RichText { match self { - Route::ManageAccount => RichText::new("Manage Account").size(24.0), Route::Thread(_) => RichText::new("Thread"), Route::Reply(_) => RichText::new("Reply"), Route::Relays => RichText::new("Relays"), @@ -44,3 +44,8 @@ impl Route { } } } + +pub enum ManageAcountRouteResponse { + AccountManagement(AccountManagementViewResponse), + AddAccount(AccountLoginResponse), +}