lib: Fix table and paragraph progress

This commit is contained in:
Erik Kundt
2024-04-20 18:11:08 +02:00
parent b176de63e7
commit 311c750f24
5 changed files with 33 additions and 4 deletions
+1 -1
View File
@@ -197,7 +197,7 @@ impl TryFrom<&Context> for State {
Ok(Self {
notifications: NotificationsState {
items: notifications,
selected: None,
selected: Some(0),
},
mode: mode.clone(),
project,
+1 -1
View File
@@ -119,7 +119,7 @@ impl TryFrom<&Context> for State {
Ok(Self {
issues: IssuesState {
items,
selected: None,
selected: Some(0),
},
mode: context.mode.clone(),
filter,
+15 -1
View File
@@ -60,6 +60,11 @@ pub struct PatchesState {
selected: Option<usize>,
}
#[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<String>,
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<Action, Selection> for State {
@@ -185,6 +195,10 @@ impl store::State<Action, Selection> for State {
self.ui.show_help = false;
None
}
Action::HelpScroll { progress } => {
self.help.progress = progress;
None
}
}
}
}
+12 -1
View File
@@ -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<State, Action> 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::<ParagraphProps>().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,
+4
View File
@@ -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<S, A> 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());
}