From 044e8f579adaabef67a9114d93bd537ec7370cdf Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Wed, 3 Apr 2024 17:13:55 +0200 Subject: [PATCH] patch: Improve search display --- bin/commands/patch/flux/select/ui.rs | 43 +++++++++++----------------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/bin/commands/patch/flux/select/ui.rs b/bin/commands/patch/flux/select/ui.rs index 3ba625c7..7a6d2d87 100644 --- a/bin/commands/patch/flux/select/ui.rs +++ b/bin/commands/patch/flux/select/ui.rs @@ -15,7 +15,6 @@ use radicle::patch::{self, Status}; use radicle_tui as tui; -use tui::flux::store::StateValue; use tui::flux::ui::items::{PatchItem, PatchItemFilter}; use tui::flux::ui::span; use tui::flux::ui::widget::container::{Footer, FooterProps, Header, HeaderProps}; @@ -175,7 +174,7 @@ impl<'a> Render<()> for ListPage<'a> { struct PatchesProps { mode: Mode, patches: Vec, - search: StateValue, + search: String, stats: HashMap, widths: [Constraint; 9], cutoff: usize, @@ -225,7 +224,7 @@ impl From<&State> for PatchesProps { Self { mode: state.mode.clone(), patches, - search: state.search.clone(), + search: state.search.read(), widths: [ Constraint::Length(3), Constraint::Length(8), @@ -418,24 +417,19 @@ impl Patches { } fn render_footer(&self, frame: &mut ratatui::Frame, area: Rect) { - let search = if self.props.search.read().is_empty() { - Line::from( - [span::default(self.props.search.read().to_string()) - .magenta() - .dim()] - .to_vec(), - ) - } else { - Line::from( - [ - span::default(" / ".to_string()).magenta().dim(), - span::default(self.props.search.read().to_string()) - .magenta() - .dim(), - ] - .to_vec(), - ) - }; + let filter = PatchItemFilter::from_str(&self.props.search).unwrap_or_default(); + + let search = Line::from( + [ + span::default(" Search ".to_string()) + .cyan() + .dim() + .reversed(), + span::default(" ".into()), + span::default(self.props.search.to_string()).gray().dim(), + ] + .to_vec(), + ); let draft = Line::from( [ @@ -486,10 +480,7 @@ impl Patches { .progress_percentage(self.props.patches.len(), self.props.page_size); let progress = span::default(format!("{}%", progress)).dim(); - match PatchItemFilter::from_str(&self.props.search.read()) - .unwrap_or_default() - .status() - { + match filter.status() { Some(state) => { let block = match state { Status::Draft => draft, @@ -637,7 +628,7 @@ impl Render for Search { frame, layout[0], TextFieldProps { - titles: ("/".into(), "Search".into()), + titles: ("Search".into(), "Search".into()), show_cursor: true, inline_label: true, },