Radish alpha
r
Radicle terminal user interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
lib: Fix table and paragraph progress
Erik Kundt committed 2 years ago
commit 311c750f241bddf5a47af7cd60d1c9ae94ffbdb0
parent b176de63e79ed288b41dc2216730419f54385a3d
5 files changed +33 -4
modified 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,
modified 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,
modified bin/commands/patch/select.rs
@@ -61,12 +61,18 @@ pub struct PatchesState {
}

#[derive(Clone, Debug)]
+
pub struct HelpState {
+
    progress: usize,
+
}
+

+
#[derive(Clone, Debug)]
pub struct State {
    patches: PatchesState,
    mode: Mode,
    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
+
            }
        }
    }
}
modified 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<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,
modified 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<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());
        }