diff --git a/bin/commands/issue/flux/select.rs b/bin/commands/issue/flux/select.rs index b50e039f..5606b92f 100644 --- a/bin/commands/issue/flux/select.rs +++ b/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, selected: Option, 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 { @@ -91,7 +91,7 @@ pub enum Action { PageSize(usize), } -impl State for IssuesState { +impl store::State for State { fn tick(&self) {} fn handle_action(&mut self, action: Action) -> Option> { @@ -116,16 +116,13 @@ impl App { pub async fn run(&self) -> Result> { let (terminator, mut interrupt_rx) = task::create_termination(); - let (store, state_rx) = Store::::new(); + let (store, state_rx) = store::Store::::new(); let (frontend, action_rx) = Frontend::::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::( - state_rx, - interrupt_rx.resubscribe() - ), + frontend.main_loop::(state_rx, interrupt_rx.resubscribe()), )?; if let Ok(reason) = interrupt_rx.recv().await { diff --git a/bin/commands/issue/flux/select/ui.rs b/bin/commands/issue/flux/select/ui.rs index 492bc72b..be4c759d 100644 --- a/bin/commands/issue/flux/select/ui.rs +++ b/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, 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, } -impl Widget for ListPage { - fn new(state: &IssuesState, action_tx: UnboundedSender) -> Self +impl Widget for ListPage { + fn new(state: &State, action_tx: UnboundedSender) -> Self where Self: Sized, { @@ -66,7 +66,7 @@ impl Widget 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 for ListPage { } } _ => { - >::handle_key_event(&mut self.issues, key); + >::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, } -impl Widget for Issues { - fn new(state: &IssuesState, action_tx: UnboundedSender) -> Self { +impl Widget for Issues { + fn new(state: &State, action_tx: UnboundedSender) -> Self { Self { action_tx: action_tx.clone(), props: IssuesProps::from(state), @@ -217,7 +219,7 @@ impl Widget 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(&self, frame: &mut ratatui::Frame, area: Rect) { + use cob::issue::State; + let filter = Line::from( [ span::default(" ".to_string()),