Radish alpha
r
Radicle terminal user interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
Implement patch browser context on home page
Erik Kundt committed 2 years ago
commit 8aef9b3775c8f7aab13e12e8f86497c7c59be4b4
parent 46f9acd75ef4eacb87ecd177ff7b486538f6bd88
3 files changed +39 -8
modified src/app/page.rs
@@ -130,7 +130,7 @@ impl HomeView {
                let state = app.state(&Cid::Home(HomeCid::IssueBrowser))?;
                let progress = match state {
                    State::Tup2((StateValue::Usize(step), StateValue::Usize(total))) => {
-
                        Progress::Step(step, total)
+
                        Progress::Step(step.saturating_add(1), total)
                    }
                    _ => Progress::None,
                };
@@ -141,7 +141,7 @@ impl HomeView {
                let state = app.state(&Cid::Home(HomeCid::PatchBrowser))?;
                let progress = match state {
                    State::Tup2((StateValue::Usize(step), StateValue::Usize(total))) => {
-
                        Progress::Step(step, total)
+
                        Progress::Step(step.saturating_add(1), total)
                    }
                    _ => Progress::None,
                };
modified src/ui/context.rs
@@ -1,4 +1,5 @@
use radicle::cob::issue::{Issue, IssueId};
+
use radicle::cob::patch::{Patch, PatchId};
use radicle::prelude::{Id, Project};
use radicle::Profile;

@@ -10,12 +11,14 @@ pub struct Context {
    project: Project,
    repository: Repository,
    issues: Vec<(IssueId, Issue)>,
+
    patches: Vec<(PatchId, Patch)>,
}

impl Context {
    pub fn new(profile: Profile, id: Id, project: Project) -> Self {
        let repository = profile.storage.repository(id).unwrap();
        let issues = crate::cob::issue::all(&repository).unwrap_or_default();
+
        let patches = crate::cob::patch::all(&repository).unwrap_or_default();

        Self {
            id,
@@ -23,6 +26,7 @@ impl Context {
            project,
            repository,
            issues,
+
            patches,
        }
    }

@@ -45,4 +49,8 @@ impl Context {
    pub fn issues(&self) -> &Vec<(IssueId, Issue)> {
        &self.issues
    }
+

+
    pub fn patches(&self) -> &Vec<(PatchId, Patch)> {
+
        &self.patches
+
    }
}
modified src/ui/widget/patch.rs
@@ -116,10 +116,33 @@ pub fn context(context: &Context, theme: &Theme, patch: (PatchId, Patch)) -> Wid
    common::context::bar(theme, "Patch", &id, title, &author, &comments.to_string())
}

-
pub fn browse_context(
-
    _context: &Context,
-
    theme: &Theme,
-
    _progress: Progress,
-
) -> Widget<ContextBar> {
-
    common::context::bar(theme, "Browse", "", "", "", "")
+
pub fn browse_context(context: &Context, theme: &Theme, progress: Progress) -> Widget<ContextBar> {
+
    use radicle::cob::patch::State;
+

+
    let patches = context.patches();
+
    let mut draft = 0;
+
    let mut open = 0;
+
    let mut archived = 0;
+
    let mut merged = 0;
+

+
    for (_, patch) in patches {
+
        match patch.state() {
+
            State::Draft => draft += 1,
+
            State::Open { conflicts: _ } => open += 1,
+
            State::Archived => archived += 1,
+
            State::Merged {
+
                commit: _,
+
                revision: _,
+
            } => merged += 1,
+
        }
+
    }
+

+
    common::context::bar(
+
        theme,
+
        "Browse",
+
        "",
+
        "",
+
        &format!("{draft} draft | {open} open | {archived} archived | {merged} merged"),
+
        &progress.to_string(),
+
    )
}