Radish alpha
r
Radicle terminal user interface
Radicle
Git (anonymous pull)
Log in to clone via SSH
issue: Rename state in selection interface
Erik Kundt committed 2 years ago
commit 255cdf771294aa54dc28ecf0e386e11870f5cc66
parent 79adc44814b69f34de106fa883b39ce6bd135765
2 files changed +29 -28
modified bin/commands/issue/flux/select.rs
@@ -10,7 +10,7 @@ use radicle::Profile;
use radicle_tui as tui;

use tui::common::cob::issue::{self, Filter};
-
use tui::flux::store::{State, Store};
+
use tui::flux::store;
use tui::flux::task::{self, Interrupted};
use tui::flux::ui::cob::IssueItem;
use tui::flux::ui::Frontend;
@@ -45,7 +45,7 @@ impl Default for UIState {
}

#[derive(Clone, Debug)]
-
pub struct IssuesState {
+
pub struct State {
    issues: Vec<IssueItem>,
    selected: Option<IssueItem>,
    mode: Mode,
@@ -53,7 +53,7 @@ pub struct IssuesState {
    ui: UIState,
}

-
impl TryFrom<&Context> for IssuesState {
+
impl TryFrom<&Context> for State {
    type Error = anyhow::Error;

    fn try_from(context: &Context) -> Result<Self, Self::Error> {
@@ -91,7 +91,7 @@ pub enum Action {
    PageSize(usize),
}

-
impl State<Action, Selection> for IssuesState {
+
impl store::State<Action, Selection> for State {
    fn tick(&self) {}

    fn handle_action(&mut self, action: Action) -> Option<Exit<Selection>> {
@@ -116,16 +116,13 @@ impl App {

    pub async fn run(&self) -> Result<Option<Selection>> {
        let (terminator, mut interrupt_rx) = task::create_termination();
-
        let (store, state_rx) = Store::<Action, IssuesState, Selection>::new();
+
        let (store, state_rx) = store::Store::<Action, State, Selection>::new();
        let (frontend, action_rx) = Frontend::<Action>::new();
-
        let state = IssuesState::try_from(&self.context)?;
+
        let state = State::try_from(&self.context)?;

        tokio::try_join!(
            store.main_loop(state, terminator, action_rx, interrupt_rx.resubscribe()),
-
            frontend.main_loop::<IssuesState, ListPage, Selection>(
-
                state_rx,
-
                interrupt_rx.resubscribe()
-
            ),
+
            frontend.main_loop::<State, ListPage, Selection>(state_rx, interrupt_rx.resubscribe()),
        )?;

        if let Ok(reason) = interrupt_rx.recv().await {
modified bin/commands/issue/flux/select/ui.rs
@@ -1,19 +1,19 @@
use std::collections::HashMap;
use std::vec;

-
use radicle::issue;
-
use ratatui::style::Stylize;
-
use ratatui::text::Line;
use tokio::sync::mpsc::UnboundedSender;

use termion::event::Key;

use ratatui::backend::Backend;
use ratatui::layout::{Constraint, Direction, Layout, Rect};
+
use ratatui::style::Stylize;
+
use ratatui::text::Line;

use radicle_tui as tui;

-
use tui::common::cob::issue::{Filter, State};
+
use tui::common::cob;
+
use tui::common::cob::issue::Filter;
use tui::flux::ui::cob::IssueItem;
use tui::flux::ui::span;
use tui::flux::ui::widget::container::{Footer, FooterProps, Header, HeaderProps};
@@ -25,15 +25,15 @@ use tui::Selection;
use crate::tui_issue::common::IssueOperation;
use crate::tui_issue::common::Mode;

-
use super::{Action, IssuesState};
+
use super::{Action, State};

pub struct ListPageProps {
    selected: Option<IssueItem>,
    mode: Mode,
}

-
impl From<&IssuesState> for ListPageProps {
-
    fn from(state: &IssuesState) -> Self {
+
impl From<&State> for ListPageProps {
+
    fn from(state: &State) -> Self {
        Self {
            selected: state.selected.clone(),
            mode: state.mode.clone(),
@@ -52,8 +52,8 @@ pub struct ListPage {
    shortcuts: Shortcuts<Action>,
}

-
impl Widget<IssuesState, Action> for ListPage {
-
    fn new(state: &IssuesState, action_tx: UnboundedSender<Action>) -> Self
+
impl Widget<State, Action> for ListPage {
+
    fn new(state: &State, action_tx: UnboundedSender<Action>) -> Self
    where
        Self: Sized,
    {
@@ -66,7 +66,7 @@ impl Widget<IssuesState, Action> for ListPage {
        .move_with_state(state)
    }

-
    fn move_with_state(self, state: &IssuesState) -> Self
+
    fn move_with_state(self, state: &State) -> Self
    where
        Self: Sized,
    {
@@ -114,7 +114,7 @@ impl Widget<IssuesState, Action> for ListPage {
                }
            }
            _ => {
-
                <Issues as Widget<IssuesState, Action>>::handle_key_event(&mut self.issues, key);
+
                <Issues as Widget<State, Action>>::handle_key_event(&mut self.issues, key);
            }
        }
    }
@@ -158,15 +158,17 @@ struct IssuesProps {
    page_size: usize,
}

-
impl From<&IssuesState> for IssuesProps {
-
    fn from(state: &IssuesState) -> Self {
+
impl From<&State> for IssuesProps {
+
    fn from(state: &State) -> Self {
+
        use radicle::issue::State;
+

        let mut open = 0;
        let mut closed = 0;

        for issue in &state.issues {
            match issue.state {
-
                issue::State::Open => open += 1,
-
                issue::State::Closed { reason: _ } => closed += 1,
+
                State::Open => open += 1,
+
                State::Closed { reason: _ } => closed += 1,
            }
        }
        let stats = HashMap::from([("Open".to_string(), open), ("Closed".to_string(), closed)]);
@@ -206,8 +208,8 @@ struct Issues {
    footer: Footer<Action>,
}

-
impl Widget<IssuesState, Action> for Issues {
-
    fn new(state: &IssuesState, action_tx: UnboundedSender<Action>) -> Self {
+
impl Widget<State, Action> for Issues {
+
    fn new(state: &State, action_tx: UnboundedSender<Action>) -> Self {
        Self {
            action_tx: action_tx.clone(),
            props: IssuesProps::from(state),
@@ -217,7 +219,7 @@ impl Widget<IssuesState, Action> for Issues {
        }
    }

-
    fn move_with_state(self, state: &IssuesState) -> Self
+
    fn move_with_state(self, state: &State) -> Self
    where
        Self: Sized,
    {
@@ -311,6 +313,8 @@ impl Issues {
    }

    fn render_footer<B: Backend>(&self, frame: &mut ratatui::Frame, area: Rect) {
+
        use cob::issue::State;
+

        let filter = Line::from(
            [
                span::default(" ".to_string()),