From 2bf3e69d77a605eb9443c8aa51d6d9c332624cdd Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Wed, 12 Jul 2023 14:06:09 +0200 Subject: [PATCH] Add empty browse context bar to home page --- src/app.rs | 1 + src/app/page.rs | 37 ++++++++++++++++++++++++++++++++- src/ui/widget/common/context.rs | 4 ++-- src/ui/widget/issue.rs | 33 +++-------------------------- src/ui/widget/patch.rs | 4 ++++ 5 files changed, 46 insertions(+), 33 deletions(-) diff --git a/src/app.rs b/src/app.rs index 7ea4aaf6..6a5996b7 100644 --- a/src/app.rs +++ b/src/app.rs @@ -28,6 +28,7 @@ pub enum HomeCid { Dashboard, IssueBrowser, PatchBrowser, + Context, Shortcuts, } diff --git a/src/app/page.rs b/src/app/page.rs index ae27dcd6..1ca9bac2 100644 --- a/src/app/page.rs +++ b/src/app/page.rs @@ -116,6 +116,31 @@ impl HomeView { .collect() } + fn update_context( + &self, + app: &mut Application, + theme: &Theme, + cid: HomeCid, + ) -> Result<()> { + let context = match cid { + HomeCid::IssueBrowser => { + let context = widget::issue::browse_context(theme); + Some(context) + } + HomeCid::PatchBrowser => { + let context = widget::patch::browse_context(theme); + Some(context) + } + _ => None, + }; + + if let Some(context) = context { + app.remount(Cid::Home(HomeCid::Context), context.to_boxed(), vec![])?; + } + + Ok(()) + } + fn update_shortcuts( &self, app: &mut Application, @@ -155,6 +180,7 @@ impl ViewPage for HomeView { let active_component = Cid::Home(self.active_component.clone()); app.active(&active_component)?; self.update_shortcuts(app, self.active_component.clone())?; + self.update_context(app, theme, self.active_component.clone())?; Ok(()) } @@ -164,6 +190,8 @@ impl ViewPage for HomeView { app.umount(&Cid::Home(HomeCid::Dashboard))?; app.umount(&Cid::Home(HomeCid::IssueBrowser))?; app.umount(&Cid::Home(HomeCid::PatchBrowser))?; + app.umount(&Cid::Home(HomeCid::Context))?; + app.umount(&Cid::Home(HomeCid::Shortcuts))?; Ok(()) } @@ -171,7 +199,7 @@ impl ViewPage for HomeView { &mut self, app: &mut Application, _context: &Context, - _theme: &Theme, + theme: &Theme, message: Message, ) -> Result> { if let Message::NavigationChanged(index) = message { @@ -179,7 +207,9 @@ impl ViewPage for HomeView { let active_component = Cid::Home(self.active_component.clone()); app.active(&active_component)?; + self.update_shortcuts(app, self.active_component.clone())?; + self.update_context(app, theme, self.active_component.clone())?; } Ok(None) @@ -196,6 +226,11 @@ impl ViewPage for HomeView { frame, layout.component, ); + + if self.active_component != HomeCid::Dashboard { + app.view(&Cid::Home(HomeCid::Context), frame, layout.context); + } + app.view(&Cid::Home(HomeCid::Shortcuts), frame, layout.shortcuts); } diff --git a/src/ui/widget/common/context.rs b/src/ui/widget/common/context.rs index 30740c13..a9442884 100644 --- a/src/ui/widget/common/context.rs +++ b/src/ui/widget/common/context.rs @@ -195,8 +195,8 @@ pub fn bar( .foreground(theme.colors.context_light) .background(theme.colors.context_bg); let comments = super::label(&format!(" {label_4} ")) - .foreground(theme.colors.context_dark) - .background(theme.colors.context_light); + .foreground(theme.colors.context_light) + .background(theme.colors.context_bg); let context_bar = ContextBar::new(context, id, author, title, comments); diff --git a/src/ui/widget/issue.rs b/src/ui/widget/issue.rs index ec7994ca..17c71a4f 100644 --- a/src/ui/widget/issue.rs +++ b/src/ui/widget/issue.rs @@ -1,17 +1,15 @@ use radicle::cob::thread::Comment; use radicle::cob::thread::CommentId; -use radicle_cli::terminal::format; use radicle::cob::issue::Issue; use radicle::cob::issue::IssueId; -use radicle::Profile; -use tuirealm::props::Color; use tuirealm::tui::layout::Constraint; use tuirealm::tui::layout::Direction; use tuirealm::tui::layout::Layout; use super::common::container::Container; use super::common::container::LabeledContainer; +use super::common::context::ContextBar; use super::common::label::Textarea; use super::common::list::List; use super::common::list::Property; @@ -21,7 +19,6 @@ use crate::ui::cob; use crate::ui::cob::IssueItem; use crate::ui::context::Context; use crate::ui::theme::Theme; -use crate::ui::widget::common::context::ContextBar; use super::*; @@ -276,30 +273,6 @@ pub fn details( Widget::new(discussion) } -pub fn context(theme: &Theme, issue: (IssueId, &Issue), profile: &Profile) -> Widget { - let (id, issue) = issue; - let is_you = *issue.author().id() == profile.did(); - - let id = format::cob(&id); - let title = issue.title(); - let author = cob::format_author(issue.author().id(), is_you); - let comments = issue.comments().count(); - - let context = common::label(" issue ").background(theme.colors.context_badge_bg); - let id = common::label(&format!(" {id} ")) - .foreground(theme.colors.context_id_fg) - .background(theme.colors.context_id_bg); - let title = common::label(&format!(" {title} ")) - .foreground(theme.colors.default_fg) - .background(theme.colors.context_bg); - let author = common::label(&format!(" {author} ")) - .foreground(theme.colors.context_id_author_fg) - .background(theme.colors.context_bg); - let comments = common::label(&format!(" {comments} ")) - .foreground(Color::Rgb(70, 70, 70)) - .background(theme.colors.context_light_bg); - - let context_bar = ContextBar::new(context, id, author, title, comments); - - Widget::new(context_bar).height(1) +pub fn browse_context(theme: &Theme) -> Widget { + common::context::bar(theme, "Browse", "", "", "", "") } diff --git a/src/ui/widget/patch.rs b/src/ui/widget/patch.rs index bb27a593..97e0279b 100644 --- a/src/ui/widget/patch.rs +++ b/src/ui/widget/patch.rs @@ -115,3 +115,7 @@ 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(theme: &Theme) -> Widget { + common::context::bar(theme, "Browse", "", "", "", "") +}