From 311c750f241bddf5a47af7cd60d1c9ae94ffbdb0 Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Wed, 17 Apr 2024 16:15:18 +0200 Subject: [PATCH] lib: Fix table and paragraph progress --- bin/commands/inbox/select.rs | 2 +- bin/commands/issue/select.rs | 2 +- bin/commands/patch/select.rs | 16 +++++++++++++++- bin/commands/patch/select/ui.rs | 13 ++++++++++++- src/ui/widget/text.rs | 4 ++++ 5 files changed, 33 insertions(+), 4 deletions(-) diff --git a/bin/commands/inbox/select.rs b/bin/commands/inbox/select.rs index d1827ee2..d1a8d79a 100644 --- a/bin/commands/inbox/select.rs +++ b/bin/commands/inbox/select.rs @@ -197,7 +197,7 @@ impl TryFrom<&Context> for State { Ok(Self { notifications: NotificationsState { items: notifications, - selected: None, + selected: Some(0), }, mode: mode.clone(), project, diff --git a/bin/commands/issue/select.rs b/bin/commands/issue/select.rs index 8f3d7372..d3655d9f 100644 --- a/bin/commands/issue/select.rs +++ b/bin/commands/issue/select.rs @@ -119,7 +119,7 @@ impl TryFrom<&Context> for State { Ok(Self { issues: IssuesState { items, - selected: None, + selected: Some(0), }, mode: context.mode.clone(), filter, diff --git a/bin/commands/patch/select.rs b/bin/commands/patch/select.rs index dbd74861..39314817 100644 --- a/bin/commands/patch/select.rs +++ b/bin/commands/patch/select.rs @@ -60,6 +60,11 @@ pub struct PatchesState { selected: Option, } +#[derive(Clone, Debug)] +pub struct HelpState { + progress: usize, +} + #[derive(Clone, Debug)] pub struct State { patches: PatchesState, @@ -67,6 +72,7 @@ pub struct State { filter: PatchItemFilter, search: store::StateValue, ui: UIState, + help: HelpState, } impl State { @@ -119,12 +125,15 @@ impl TryFrom<&Context> for State { Ok(Self { patches: PatchesState { items, - selected: None, + selected: Some(0), }, mode: context.mode.clone(), filter, search, ui: UIState::default(), + help: HelpState { + progress: 0, + } }) } } @@ -139,6 +148,7 @@ pub enum Action { CloseSearch, OpenHelp, CloseHelp, + HelpScroll { progress: usize }, } impl store::State for State { @@ -185,6 +195,10 @@ impl store::State for State { self.ui.show_help = false; None } + Action::HelpScroll { progress } => { + self.help.progress = progress; + None + } } } } diff --git a/bin/commands/patch/select/ui.rs b/bin/commands/patch/select/ui.rs index 593276fc..09a8c403 100644 --- a/bin/commands/patch/select/ui.rs +++ b/bin/commands/patch/select/ui.rs @@ -604,6 +604,7 @@ pub struct HelpProps<'a> { content: Text<'a>, focus: bool, page_size: usize, + progress: usize, } impl<'a> From<&State> for HelpProps<'a> { @@ -748,6 +749,7 @@ impl<'a> From<&State> for HelpProps<'a> { content, focus: false, page_size: state.ui.page_size, + progress: state.help.progress, } } } @@ -781,6 +783,15 @@ impl<'a, B: Backend> View for Help<'a, B> { props: HelpProps::from(state), header: Header::new(state, action_tx.clone()).to_boxed(), content: Paragraph::new(state, action_tx.clone()) + .on_change(|props, action_tx| { + props.downcast_ref::().and_then(|props| { + action_tx + .send(Action::HelpScroll { + progress: props.progress.clone(), + }) + .ok() + }); + }) .on_update(|state| { let props = HelpProps::from(state); @@ -843,7 +854,7 @@ where Constraint::Length(3), ]) .areas(area); - let progress = span::default(format!("{}%", 0)).dim(); + let progress = span::default(format!("{}%", props.progress)).dim(); self.header.render( frame, diff --git a/src/ui/widget/text.rs b/src/ui/widget/text.rs index 70b1c001..7c6aa509 100644 --- a/src/ui/widget/text.rs +++ b/src/ui/widget/text.rs @@ -20,6 +20,7 @@ pub struct ParagraphProps<'a> { pub has_header: bool, pub has_footer: bool, pub page_size: usize, + pub progress: usize, } impl<'a> ParagraphProps<'a> { @@ -47,6 +48,7 @@ impl<'a> Default for ParagraphProps<'a> { has_header: false, has_footer: false, page_size: 1, + progress: 0, } } } @@ -204,6 +206,8 @@ impl<'a: 'static, S, A> View for Paragraph<'a, S, A> { _ => {} } + self.progress = self.offset; + if let Some(on_change) = self.on_change { (on_change)(&self.props, self.action_tx.clone()); }