diff --git a/node-launchpad/src/components/discord_username.rs b/node-launchpad/src/components/discord_username.rs index 6127ca2d5c..beac963208 100644 --- a/node-launchpad/src/components/discord_username.rs +++ b/node-launchpad/src/components/discord_username.rs @@ -17,7 +17,8 @@ use ratatui::{prelude::*, widgets::*}; use tui_input::{backend::crossterm::EventHandler, Input}; pub struct DiscordUsernameInputBox { - show_scene: bool, + /// Whether the component is active right now, capturing keystrokes + draw things. + active: bool, discord_input_filed: Input, // cache the old value incase user presses Esc. old_value: String, @@ -26,7 +27,7 @@ pub struct DiscordUsernameInputBox { impl DiscordUsernameInputBox { pub fn new(username: String) -> Self { Self { - show_scene: false, + active: false, discord_input_filed: Input::default().with_value(username), old_value: Default::default(), } @@ -35,6 +36,9 @@ impl DiscordUsernameInputBox { impl Component for DiscordUsernameInputBox { fn handle_key_events(&mut self, key: KeyEvent) -> Result> { + if !self.active { + return Ok(vec![]); + } // while in entry mode, keybinds are not captured, so gotta exit entry mode from here let send_back = match key.code { KeyCode::Enter => { @@ -79,14 +83,14 @@ impl Component for DiscordUsernameInputBox { let send_back = match action { Action::SwitchScene(scene) => match scene { Scene::DiscordUsernameInputBox => { - self.show_scene = true; + self.active = true; self.old_value = self.discord_input_filed.value().to_string(); // set to entry input mode as we want to handle everything within our handle_key_events // so by default if this scene is active, we capture inputs. Some(Action::SwitchInputMode(InputMode::Entry)) } _ => { - self.show_scene = false; + self.active = false; None } }, @@ -96,7 +100,7 @@ impl Component for DiscordUsernameInputBox { } fn draw(&mut self, f: &mut crate::tui::Frame<'_>, area: Rect) -> Result<()> { - if !self.show_scene { + if !self.active { return Ok(()); } diff --git a/node-launchpad/src/components/footer.rs b/node-launchpad/src/components/footer.rs index ca33c26e13..7a21041354 100644 --- a/node-launchpad/src/components/footer.rs +++ b/node-launchpad/src/components/footer.rs @@ -35,11 +35,11 @@ impl Component for Footer { let text: Cow<_> = match self.current_scene { Scene::Home => { - "[Ctrl+g] Start nodes, [Ctrl+x] Stop node, [O] Set Resources, [D]iscord Username, [Q]uit".into() + "[Ctrl+g] Start nodes, [Ctrl+x] Stop nodes, [O] Set Resources, [D]iscord Username, [Q]uit".into() } Scene::Options => "none".into(), Scene::DiscordUsernameInputBox => "⏎ Accept, [Esc] Cancel".into(), - Scene::ResourceAllocationInputBox => format!("⏎ Accept, [Esc] Cancel.").into(), + Scene::ResourceAllocationInputBox => "⏎ Accept, [Esc] Cancel.".into(), }; f.render_widget( diff --git a/node-launchpad/src/components/home.rs b/node-launchpad/src/components/home.rs index 6c5c91a2bd..ed723da0cf 100644 --- a/node-launchpad/src/components/home.rs +++ b/node-launchpad/src/components/home.rs @@ -24,10 +24,11 @@ use tokio::sync::mpsc::UnboundedSender; const NODE_START_INTERVAL: usize = 10; pub struct Home { + /// Whether the component is active right now, capturing keystrokes + draw things. + active: bool, action_sender: Option>, config: Config, // state - show_scene: bool, node_services: Vec, node_table_state: TableState, allocated_disk_space: usize, @@ -41,7 +42,7 @@ impl Home { let mut home = Self { action_sender: Default::default(), config: Default::default(), - show_scene: true, + active: true, node_services: Default::default(), allocated_disk_space, node_table_state: Default::default(), @@ -165,14 +166,14 @@ impl Component for Home { match action { Action::SwitchScene(scene) => match scene { Scene::Home => { - self.show_scene = true; + self.active = true; // make sure we're in navigation mode return Ok(Some(Action::SwitchInputMode(InputMode::Navigation))); } Scene::DiscordUsernameInputBox | Scene::ResourceAllocationInputBox => { - self.show_scene = true + self.active = true } - _ => self.show_scene = false, + _ => self.active = false, }, Action::StoreAllocatedDiskSpace(space) => { self.allocated_disk_space = space; @@ -281,7 +282,7 @@ impl Component for Home { } fn draw(&mut self, f: &mut Frame<'_>, area: Rect) -> Result<()> { - if !self.show_scene { + if !self.active { return Ok(()); } diff --git a/node-launchpad/src/components/resource_allocation.rs b/node-launchpad/src/components/resource_allocation.rs index ee5b0ddb96..aff46a270c 100644 --- a/node-launchpad/src/components/resource_allocation.rs +++ b/node-launchpad/src/components/resource_allocation.rs @@ -23,7 +23,8 @@ use super::{utils::centered_rect_fixed, Component}; pub const GB_PER_NODE: usize = 5; pub struct ResourceAllocationInputBox { - show_scene: bool, + /// Whether the component is active right now, capturing keystrokes + draw things. + active: bool, available_disk_space_bytes: usize, allocated_space_input: Input, // cache the old value incase user presses Esc. @@ -33,7 +34,7 @@ pub struct ResourceAllocationInputBox { impl ResourceAllocationInputBox { pub fn new(allocated_space: usize) -> Result { let new = Self { - show_scene: false, + active: false, available_disk_space_bytes: Self::get_available_space_gb()?, allocated_space_input: Input::default().with_value(allocated_space.to_string()), old_value: Default::default(), @@ -66,6 +67,10 @@ impl ResourceAllocationInputBox { impl Component for ResourceAllocationInputBox { fn handle_key_events(&mut self, key: KeyEvent) -> Result> { + if !self.active { + return Ok(vec![]); + } + // while in entry mode, keybinds are not captured, so gotta exit entry mode from here let send_back = match key.code { KeyCode::Enter => { @@ -124,14 +129,14 @@ impl Component for ResourceAllocationInputBox { let send_back = match action { Action::SwitchScene(scene) => match scene { Scene::ResourceAllocationInputBox => { - self.show_scene = true; + self.active = true; self.old_value = self.allocated_space_input.value().to_string(); // set to entry input mode as we want to handle everything within our handle_key_events // so by default if this scene is active, we capture inputs. Some(Action::SwitchInputMode(InputMode::Entry)) } _ => { - self.show_scene = false; + self.active = false; None } }, @@ -141,7 +146,7 @@ impl Component for ResourceAllocationInputBox { } fn draw(&mut self, f: &mut crate::tui::Frame<'_>, area: Rect) -> Result<()> { - if !self.show_scene { + if !self.active { return Ok(()); }