notedeck

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

commit ee0029268f1b16f26383b710e760abce3060c1c8
parent df4e331d33e3a6e7bd9afb6eae1c5214a2ae2736
Author: kernelkind <kernelkind@gmail.com>
Date:   Fri,  6 Sep 2024 18:31:50 -0400

add RoutableWidgetState conception

holds the routes for an arbitrary widget

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

Diffstat:
Msrc/app.rs | 11+++++------
Msrc/lib.rs | 1+
Asrc/routable_widget_state.rs | 26++++++++++++++++++++++++++
Msrc/route.rs | 29+++++++++++++++++------------
4 files changed, 49 insertions(+), 18 deletions(-)

diff --git 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<ManageAccountRoute>, 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 @@ -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 @@ -0,0 +1,26 @@ +#[derive(Default)] +pub struct RoutableWidgetState<R: Clone> { + routes: Vec<R>, +} + +impl<R: Clone> RoutableWidgetState<R> { + 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<R> { + self.routes.last().cloned() + } + + pub fn get_routes(&self) -> Vec<R> { + self.routes.clone() + } +} diff --git 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<Response> { - 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), +}