From 11214734ae44a6deccd9d0236aec99d290128ef7 Mon Sep 17 00:00:00 2001 From: filipriec Date: Wed, 26 Mar 2025 00:26:36 +0100 Subject: [PATCH] functions are now in the file dedicated to the functions belonging to the page --- client/src/modes/general/navigation.rs | 29 +++----------------------- client/src/tui/functions.rs | 7 +++++++ client/src/tui/functions/admin.rs | 8 +++++++ client/src/tui/functions/intro.rs | 23 ++++++++++++++++++++ client/src/tui/mod.rs | 1 + 5 files changed, 42 insertions(+), 26 deletions(-) create mode 100644 client/src/tui/functions.rs create mode 100644 client/src/tui/functions/admin.rs create mode 100644 client/src/tui/functions/intro.rs diff --git a/client/src/modes/general/navigation.rs b/client/src/modes/general/navigation.rs index 57851d3..9628e26 100644 --- a/client/src/modes/general/navigation.rs +++ b/client/src/modes/general/navigation.rs @@ -4,6 +4,7 @@ use crossterm::event::KeyEvent; use crate::config::binds::config::Config; use crate::state::state::AppState; use crate::state::pages::form::FormState; +use crate::tui::functions::{intro, admin}; pub async fn handle_navigation_event( key: KeyEvent, @@ -123,33 +124,9 @@ pub fn previous_option(app_state: &mut AppState) { pub fn select(app_state: &mut AppState) { if app_state.ui.show_intro { - // Handle selection in intro screen - match app_state.ui.intro_state.selected_option { - 0 => { // Continue - show form - app_state.ui.show_form = true; - app_state.ui.show_admin = false; - app_state.ui.show_login = false; - } - 1 => { // Admin - app_state.ui.show_form = false; - app_state.ui.show_admin = true; - app_state.ui.show_login = false; - } - 2 => { // Login - app_state.ui.show_form = false; - app_state.ui.show_admin = false; - app_state.ui.show_login = true; - } - _ => {} // Other options (shouldn't happen) - } - app_state.ui.show_intro = false; + intro::handle_intro_selection(app_state); } else if app_state.ui.show_admin { - // Handle selection in admin panel - let profiles = &app_state.profile_tree.profiles; - if !profiles.is_empty() && app_state.general.selected_item < profiles.len() { - // Set the selected profile - app_state.selected_profile = Some(profiles[app_state.general.selected_item].name.clone()); - } + admin::handle_admin_selection(app_state); } } diff --git a/client/src/tui/functions.rs b/client/src/tui/functions.rs new file mode 100644 index 0000000..ab72dd8 --- /dev/null +++ b/client/src/tui/functions.rs @@ -0,0 +1,7 @@ +// src/tui/functions.rs + +pub mod admin; +pub mod intro; + +pub use admin::*; +pub use intro::*; diff --git a/client/src/tui/functions/admin.rs b/client/src/tui/functions/admin.rs new file mode 100644 index 0000000..91966cb --- /dev/null +++ b/client/src/tui/functions/admin.rs @@ -0,0 +1,8 @@ +use crate::state::state::AppState; + +pub fn handle_admin_selection(app_state: &mut AppState) { + let profiles = &app_state.profile_tree.profiles; + if !profiles.is_empty() && app_state.general.selected_item < profiles.len() { + app_state.selected_profile = Some(profiles[app_state.general.selected_item].name.clone()); + } +} diff --git a/client/src/tui/functions/intro.rs b/client/src/tui/functions/intro.rs new file mode 100644 index 0000000..923337d --- /dev/null +++ b/client/src/tui/functions/intro.rs @@ -0,0 +1,23 @@ +use crate::state::state::AppState; + +pub fn handle_intro_selection(app_state: &mut AppState) { + match app_state.ui.intro_state.selected_option { + 0 => { // Continue + app_state.ui.show_form = true; + app_state.ui.show_admin = false; + app_state.ui.show_login = false; + } + 1 => { // Admin + app_state.ui.show_form = false; + app_state.ui.show_admin = true; + app_state.ui.show_login = false; + } + 2 => { // Login + app_state.ui.show_form = false; + app_state.ui.show_admin = false; + app_state.ui.show_login = true; + } + _ => {} + } + app_state.ui.show_intro = false; +} diff --git a/client/src/tui/mod.rs b/client/src/tui/mod.rs index fe59c76..546ed51 100644 --- a/client/src/tui/mod.rs +++ b/client/src/tui/mod.rs @@ -1,4 +1,5 @@ // src/tui/mod.rs pub mod terminal; pub mod controls; +pub mod functions;