From 52b47a7cd5e64d43dc2f834f286955ac9f27fd9a Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Thu, 21 Mar 2024 23:54:06 +0100 Subject: [PATCH] patch: Rename state --- bin/commands/patch/flux/select.rs | 18 ++++++------- bin/commands/patch/flux/select/ui.rs | 38 ++++++++++++++-------------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/bin/commands/patch/flux/select.rs b/bin/commands/patch/flux/select.rs index 736df1c7..3c3b881d 100644 --- a/bin/commands/patch/flux/select.rs +++ b/bin/commands/patch/flux/select.rs @@ -10,7 +10,7 @@ use radicle::Profile; use radicle_tui as tui; use tui::common::cob::patch::{self, Filter}; -use tui::flux::store::{State, StateValue, Store}; +use tui::flux::store; use tui::flux::task::{self, Interrupted}; use tui::flux::ui::items::PatchItem; use tui::flux::ui::Frontend; @@ -49,15 +49,15 @@ impl Default for UIState { } #[derive(Clone, Debug)] -pub struct PatchesState { +pub struct State { patches: Vec, selected: Option, mode: Mode, - search: StateValue, + search: store::StateValue, ui: UIState, } -impl TryFrom<&Context> for PatchesState { +impl TryFrom<&Context> for State { type Error = anyhow::Error; fn try_from(context: &Context) -> Result { @@ -77,7 +77,7 @@ impl TryFrom<&Context> for PatchesState { patches: items, selected, mode: context.mode.clone(), - search: StateValue::new(context.filter.to_string()), + search: store::StateValue::new(context.filter.to_string()), ui: UIState::default(), }) } @@ -93,7 +93,7 @@ pub enum Action { CloseSearch, } -impl State for PatchesState { +impl store::State for State { fn tick(&self) {} fn handle_action(&mut self, action: Action) -> Option> { @@ -136,13 +136,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 = PatchesState::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::( + frontend.main_loop::( state_rx, interrupt_rx.resubscribe() ), diff --git a/bin/commands/patch/flux/select/ui.rs b/bin/commands/patch/flux/select/ui.rs index 009dd749..492dc1df 100644 --- a/bin/commands/patch/flux/select/ui.rs +++ b/bin/commands/patch/flux/select/ui.rs @@ -11,7 +11,7 @@ use termion::event::Key; use ratatui::backend::Backend; use ratatui::layout::{Constraint, Layout, Rect}; use ratatui::style::Stylize; -use ratatui::text::Line; +use ratatui::text::{Line, Text}; use radicle_tui as tui; @@ -28,7 +28,7 @@ use tui::Selection; use crate::tui_patch::common::Mode; use crate::tui_patch::common::PatchOperation; -use super::{Action, PatchesState}; +use super::{Action, State}; pub struct ListPageProps { selected: Option, @@ -36,8 +36,8 @@ pub struct ListPageProps { show_search: bool, } -impl From<&PatchesState> for ListPageProps { - fn from(state: &PatchesState) -> Self { +impl From<&State> for ListPageProps { + fn from(state: &State) -> Self { Self { selected: state.selected.clone(), mode: state.mode.clone(), @@ -59,8 +59,8 @@ pub struct ListPage { shortcuts: Shortcuts, } -impl Widget for ListPage { - fn new(state: &PatchesState, action_tx: UnboundedSender) -> Self +impl Widget for ListPage { + fn new(state: &State, action_tx: UnboundedSender) -> Self where Self: Sized, { @@ -74,7 +74,7 @@ impl Widget for ListPage { .move_with_state(state) } - fn move_with_state(self, state: &PatchesState) -> Self + fn move_with_state(self, state: &State) -> Self where Self: Sized, { @@ -93,7 +93,7 @@ impl Widget for ListPage { fn handle_key_event(&mut self, key: termion::event::Key) { if self.props.show_search { - >::handle_key_event(&mut self.search, key) + >::handle_key_event(&mut self.search, key) } else { match key { Key::Esc | Key::Ctrl('c') => { @@ -142,7 +142,7 @@ impl Widget for ListPage { let _ = self.action_tx.send(Action::OpenSearch); } _ => { - >::handle_key_event( + >::handle_key_event( &mut self.patches, key, ); @@ -211,8 +211,8 @@ struct PatchesProps { show_search: bool, } -impl From<&PatchesState> for PatchesProps { - fn from(state: &PatchesState) -> Self { +impl From<&State> for PatchesProps { + fn from(state: &State) -> Self { let mut draft = 0; let mut open = 0; let mut archived = 0; @@ -285,8 +285,8 @@ struct Patches { footer: Footer, } -impl Widget for Patches { - fn new(state: &PatchesState, action_tx: UnboundedSender) -> Self { +impl Widget for Patches { + fn new(state: &State, action_tx: UnboundedSender) -> Self { Self { action_tx: action_tx.clone(), props: PatchesProps::from(state), @@ -296,7 +296,7 @@ impl Widget for Patches { } } - fn move_with_state(self, state: &PatchesState) -> Self + fn move_with_state(self, state: &State) -> Self where Self: Sized, { @@ -566,8 +566,8 @@ pub struct Search { pub input: TextField, } -impl Widget for Search { - fn new(state: &PatchesState, action_tx: UnboundedSender) -> Self +impl Widget for Search { + fn new(state: &State, action_tx: UnboundedSender) -> Self where Self: Sized, { @@ -577,12 +577,12 @@ impl Widget for Search { Self { action_tx, input }.move_with_state(state) } - fn move_with_state(self, state: &PatchesState) -> Self + fn move_with_state(self, state: &State) -> Self where Self: Sized, { let mut input = - >::move_with_state(self.input, state); + >::move_with_state(self.input, state); input.set_text(&state.search.read().to_string()); Self { input, ..self } @@ -601,7 +601,7 @@ impl Widget for Search { let _ = self.action_tx.send(Action::ApplySearch); } _ => { - >::handle_key_event(&mut self.input, key); + >::handle_key_event(&mut self.input, key); let _ = self.action_tx.send(Action::UpdateSearch { value: self.input.text().to_string(), });