tui: Move application context to separate module

This commit is contained in:
Erik Kundt 2023-06-02 10:54:41 +02:00
parent 64708954ca
commit 0eb37431ff
4 changed files with 46 additions and 22 deletions

View File

@ -14,6 +14,7 @@ use tuirealm::application::PollStrategy;
use tuirealm::{Application, Frame, NoUserEvent}; use tuirealm::{Application, Frame, NoUserEvent};
use radicle_tui::ui; use radicle_tui::ui;
use radicle_tui::ui::context::Context;
use radicle_tui::ui::theme::{self, Theme}; use radicle_tui::ui::theme::{self, Theme};
use radicle_tui::Tui; use radicle_tui::Tui;
@ -76,12 +77,6 @@ pub enum Message {
Quit, Quit,
} }
pub struct Context {
profile: Profile,
id: Id,
project: Project,
}
#[allow(dead_code)] #[allow(dead_code)]
pub struct App { pub struct App {
context: Context, context: Context,
@ -95,11 +90,7 @@ pub struct App {
impl App { impl App {
pub fn new(profile: Profile, id: Id, project: Project) -> Self { pub fn new(profile: Profile, id: Id, project: Project) -> Self {
Self { Self {
context: Context { context: Context::new(profile, id, project),
id,
profile,
project,
},
pages: PageStack::default(), pages: PageStack::default(),
theme: theme::default_dark(), theme: theme::default_dark(),
quit: false, quit: false,
@ -125,9 +116,9 @@ impl App {
) -> Result<()> { ) -> Result<()> {
let repo = self let repo = self
.context .context
.profile .profile()
.storage .storage
.repository(self.context.id) .repository(*self.context.id())
.unwrap(); .unwrap();
let patches = Patches::open(&repo).unwrap(); let patches = Patches::open(&repo).unwrap();
@ -151,9 +142,9 @@ impl App {
) -> Result<()> { ) -> Result<()> {
let repo = self let repo = self
.context .context
.profile .profile()
.storage .storage
.repository(self.context.id) .repository(*self.context.id())
.unwrap(); .unwrap();
let issues = Issues::open(&repo).unwrap(); let issues = Issues::open(&repo).unwrap();

View File

@ -5,11 +5,12 @@ use radicle::cob::patch::{Patch, PatchId};
use tuirealm::{Frame, NoUserEvent, Sub, SubClause}; use tuirealm::{Frame, NoUserEvent, Sub, SubClause};
use radicle_tui::ui::context::Context;
use radicle_tui::ui::layout; use radicle_tui::ui::layout;
use radicle_tui::ui::theme::Theme; use radicle_tui::ui::theme::Theme;
use radicle_tui::ui::widget; 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. /// `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 /// Building deep nested component hierarchies would need a lot more additional effort to
@ -74,9 +75,10 @@ impl ViewPage for HomeView {
) -> Result<()> { ) -> Result<()> {
let navigation = widget::home::navigation(theme).to_boxed(); let navigation = widget::home::navigation(theme).to_boxed();
let dashboard = widget::home::dashboard(theme, &context.id, &context.project).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 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 patch_browser =
widget::home::patches(theme, context.id(), context.profile()).to_boxed();
app.remount(Cid::Home(HomeCid::Navigation), navigation, vec![])?; app.remount(Cid::Home(HomeCid::Navigation), navigation, vec![])?;
@ -162,7 +164,7 @@ impl ViewPage for IssuePage {
theme: &Theme, theme: &Theme,
) -> Result<()> { ) -> Result<()> {
let (id, issue) = &self.issue; 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.remount(Cid::Issue(IssueCid::List), list, vec![])?;
app.active(&self.active_component)?; app.active(&self.active_component)?;
@ -238,8 +240,8 @@ impl ViewPage for PatchView {
) -> Result<()> { ) -> Result<()> {
let (id, patch) = &self.patch; let (id, patch) = &self.patch;
let navigation = widget::patch::navigation(theme).to_boxed(); let navigation = widget::patch::navigation(theme).to_boxed();
let activity = widget::patch::activity(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(); 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::Navigation), navigation, vec![])?;
app.remount(Cid::Patch(PatchCid::Activity), activity, vec![])?; app.remount(Cid::Patch(PatchCid::Activity), activity, vec![])?;

View File

@ -1,4 +1,5 @@
pub mod cob; pub mod cob;
pub mod context;
pub mod ext; pub mod ext;
pub mod layout; pub mod layout;
pub mod state; pub mod state;

View File

@ -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
}
}