From d54f20f1bd032512ecfe5694affa4bd9d01de992 Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Wed, 24 Apr 2024 14:37:32 +0200 Subject: [PATCH] inbox: Move out browse footer --- bin/commands/inbox/select/ui.rs | 124 ++++++++++++++++---------------- 1 file changed, 60 insertions(+), 64 deletions(-) diff --git a/bin/commands/inbox/select/ui.rs b/bin/commands/inbox/select/ui.rs index 02f1e2a4..190e646d 100644 --- a/bin/commands/inbox/select/ui.rs +++ b/bin/commands/inbox/select/ui.rs @@ -116,69 +116,6 @@ pub struct BrowsePage<'a> { shortcuts: BoxedWidget, } -impl<'a> BrowsePage<'a> { - fn build_footer(props: &BrowsePageProps<'a>, selected: Option) -> Vec> { - let search = Line::from(vec![ - span::default(" Search ").cyan().dim().reversed(), - span::default(" "), - span::default(&props.search.to_string()).gray().dim(), - ]); - - let seen = Line::from(vec![ - span::positive(&props.stats.get("Seen").unwrap_or(&0).to_string()).dim(), - span::default(" Seen").dim(), - ]); - let unseen = Line::from(vec![ - span::positive(&props.stats.get("Unseen").unwrap_or(&0).to_string()) - .magenta() - .dim(), - span::default(" Unseen").dim(), - ]); - - let progress = selected - .map(|selected| { - TableUtils::progress(selected, props.notifications.len(), props.page_size) - }) - .unwrap_or_default(); - let progress = span::default(&format!("{}%", progress)).dim(); - - match NotificationItemFilter::from_str(&props.search) - .unwrap_or_default() - .state() - { - Some(state) => { - let block = match state { - NotificationState::Seen => seen, - NotificationState::Unseen => unseen, - }; - - [ - Column::new(Text::from(search), Constraint::Fill(1)), - Column::new( - Text::from(block.clone()), - Constraint::Min(block.width() as u16), - ), - Column::new(Text::from(progress), Constraint::Min(4)), - ] - .to_vec() - } - None => [ - Column::new(Text::from(search), Constraint::Fill(1)), - Column::new( - Text::from(seen.clone()), - Constraint::Min(seen.width() as u16), - ), - Column::new( - Text::from(unseen.clone()), - Constraint::Min(unseen.width() as u16), - ), - Column::new(Text::from(progress), Constraint::Min(4)), - ] - .to_vec(), - } - } -} - impl<'a: 'static> Widget for BrowsePage<'a> { type Action = Action; type State = State; @@ -241,7 +178,7 @@ impl<'a: 'static> Widget for BrowsePage<'a> { let props = BrowsePageProps::from(state); FooterProps::default() - .columns(Self::build_footer(&props, props.selected)) + .columns(browse_footer(&props, props.selected)) .to_boxed() }) .to_boxed(), @@ -617,6 +554,65 @@ impl<'a: 'static> Widget for HelpPage<'a> { } } +fn browse_footer<'a>(props: &BrowsePageProps<'a>, selected: Option) -> Vec> { + let search = Line::from(vec![ + span::default(" Search ").cyan().dim().reversed(), + span::default(" "), + span::default(&props.search.to_string()).gray().dim(), + ]); + + let seen = Line::from(vec![ + span::positive(&props.stats.get("Seen").unwrap_or(&0).to_string()).dim(), + span::default(" Seen").dim(), + ]); + let unseen = Line::from(vec![ + span::positive(&props.stats.get("Unseen").unwrap_or(&0).to_string()) + .magenta() + .dim(), + span::default(" Unseen").dim(), + ]); + + let progress = selected + .map(|selected| TableUtils::progress(selected, props.notifications.len(), props.page_size)) + .unwrap_or_default(); + let progress = span::default(&format!("{}%", progress)).dim(); + + match NotificationItemFilter::from_str(&props.search) + .unwrap_or_default() + .state() + { + Some(state) => { + let block = match state { + NotificationState::Seen => seen, + NotificationState::Unseen => unseen, + }; + + [ + Column::new(Text::from(search), Constraint::Fill(1)), + Column::new( + Text::from(block.clone()), + Constraint::Min(block.width() as u16), + ), + Column::new(Text::from(progress), Constraint::Min(4)), + ] + .to_vec() + } + None => [ + Column::new(Text::from(search), Constraint::Fill(1)), + Column::new( + Text::from(seen.clone()), + Constraint::Min(seen.width() as u16), + ), + Column::new( + Text::from(unseen.clone()), + Constraint::Min(unseen.width() as u16), + ), + Column::new(Text::from(progress), Constraint::Min(4)), + ] + .to_vec(), + } +} + fn help_text() -> Text<'static> { Text::from( [