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 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();

View File

@ -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![])?;

View File

@ -1,4 +1,5 @@
pub mod cob;
pub mod context;
pub mod ext;
pub mod layout;
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
}
}