Radish alpha
r
Radicle terminal user interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
tui: Move application context to separate module
Erik Kundt committed 2 years ago
commit e0de4cf2092edea7b452a19c841fb3cbf9570786
parent 66421f708899c4e1304b1c1bd31b8ad9152df65d
4 files changed +46 -22
modified 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();

modified 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![])?;
modified radicle-tui/src/ui.rs
@@ -1,4 +1,5 @@
pub mod cob;
+
pub mod context;
pub mod ext;
pub mod layout;
pub mod state;
added 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
+
    }
+
}