From 0eb37431ffe8286df6e0f012047d587b242ff876 Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Fri, 2 Jun 2023 10:54:41 +0200 Subject: [PATCH] tui: Move application context to separate module --- radicle-tui/src/app.rs | 21 ++++++--------------- radicle-tui/src/app/page.rs | 16 +++++++++------- radicle-tui/src/ui.rs | 1 + radicle-tui/src/ui/context.rs | 30 ++++++++++++++++++++++++++++++ 4 files changed, 46 insertions(+), 22 deletions(-) create mode 100644 radicle-tui/src/ui/context.rs diff --git a/radicle-tui/src/app.rs b/radicle-tui/src/app.rs index 8d7f237d..9a32c737 100644 --- a/radicle-tui/src/app.rs +++ b/radicle-tui/src/app.rs @@ -14,6 +14,7 @@ use tuirealm::application::PollStrategy; use tuirealm::{Application, Frame, NoUserEvent}; use radicle_tui::ui; +use radicle_tui::ui::context::Context; use radicle_tui::ui::theme::{self, Theme}; use radicle_tui::Tui; @@ -76,12 +77,6 @@ pub enum Message { Quit, } -pub struct Context { - profile: Profile, - id: Id, - project: Project, -} - #[allow(dead_code)] pub struct App { context: Context, @@ -95,11 +90,7 @@ pub struct App { impl App { pub fn new(profile: Profile, id: Id, project: Project) -> Self { Self { - context: Context { - id, - profile, - project, - }, + context: Context::new(profile, id, project), pages: PageStack::default(), theme: theme::default_dark(), quit: false, @@ -125,9 +116,9 @@ impl App { ) -> Result<()> { let repo = self .context - .profile + .profile() .storage - .repository(self.context.id) + .repository(*self.context.id()) .unwrap(); let patches = Patches::open(&repo).unwrap(); @@ -151,9 +142,9 @@ impl App { ) -> Result<()> { let repo = self .context - .profile + .profile() .storage - .repository(self.context.id) + .repository(*self.context.id()) .unwrap(); let issues = Issues::open(&repo).unwrap(); diff --git a/radicle-tui/src/app/page.rs b/radicle-tui/src/app/page.rs index 9615dfbb..89be284d 100644 --- a/radicle-tui/src/app/page.rs +++ b/radicle-tui/src/app/page.rs @@ -5,11 +5,12 @@ use radicle::cob::patch::{Patch, PatchId}; use tuirealm::{Frame, NoUserEvent, Sub, SubClause}; +use radicle_tui::ui::context::Context; use radicle_tui::ui::layout; use radicle_tui::ui::theme::Theme; use radicle_tui::ui::widget; -use super::{subscription, Application, Cid, Context, HomeCid, IssueCid, Message, PatchCid}; +use super::{subscription, Application, Cid, HomeCid, IssueCid, Message, PatchCid}; /// `tuirealm`'s event and prop system is designed to work with flat component hierarchies. /// Building deep nested component hierarchies would need a lot more additional effort to @@ -74,9 +75,10 @@ impl ViewPage for HomeView { ) -> Result<()> { let navigation = widget::home::navigation(theme).to_boxed(); - let dashboard = widget::home::dashboard(theme, &context.id, &context.project).to_boxed(); - let issue_browser = widget::home::issues(theme, &context.id, &context.profile).to_boxed(); - let patch_browser = widget::home::patches(theme, &context.id, &context.profile).to_boxed(); + let dashboard = widget::home::dashboard(theme, context.id(), context.project()).to_boxed(); + let issue_browser = widget::home::issues(theme, context.id(), context.profile()).to_boxed(); + let patch_browser = + widget::home::patches(theme, context.id(), context.profile()).to_boxed(); app.remount(Cid::Home(HomeCid::Navigation), navigation, vec![])?; @@ -162,7 +164,7 @@ impl ViewPage for IssuePage { theme: &Theme, ) -> Result<()> { let (id, issue) = &self.issue; - let list = widget::issue::list(theme, (*id, issue), &context.profile).to_boxed(); + let list = widget::issue::list(theme, (*id, issue), context.profile()).to_boxed(); app.remount(Cid::Issue(IssueCid::List), list, vec![])?; app.active(&self.active_component)?; @@ -238,8 +240,8 @@ impl ViewPage for PatchView { ) -> Result<()> { let (id, patch) = &self.patch; let navigation = widget::patch::navigation(theme).to_boxed(); - let activity = widget::patch::activity(theme, (*id, patch), &context.profile).to_boxed(); - let files = widget::patch::files(theme, (*id, patch), &context.profile).to_boxed(); + let activity = widget::patch::activity(theme, (*id, patch), context.profile()).to_boxed(); + let files = widget::patch::files(theme, (*id, patch), context.profile()).to_boxed(); app.remount(Cid::Patch(PatchCid::Navigation), navigation, vec![])?; app.remount(Cid::Patch(PatchCid::Activity), activity, vec![])?; diff --git a/radicle-tui/src/ui.rs b/radicle-tui/src/ui.rs index f0ed1024..c82eda00 100644 --- a/radicle-tui/src/ui.rs +++ b/radicle-tui/src/ui.rs @@ -1,4 +1,5 @@ pub mod cob; +pub mod context; pub mod ext; pub mod layout; pub mod state; diff --git a/radicle-tui/src/ui/context.rs b/radicle-tui/src/ui/context.rs new file mode 100644 index 00000000..0f634224 --- /dev/null +++ b/radicle-tui/src/ui/context.rs @@ -0,0 +1,30 @@ +use radicle::prelude::{Id, Project}; +use radicle::Profile; + +pub struct Context { + profile: Profile, + id: Id, + project: Project, +} + +impl Context { + pub fn new(profile: Profile, id: Id, project: Project) -> Self { + Self { + id, + profile, + project, + } + } + + pub fn profile(&self) -> &Profile { + &self.profile + } + + pub fn id(&self) -> &Id { + &self.id + } + + pub fn project(&self) -> &Project { + &self.project + } +}