functions are now in the file dedicated to the functions belonging to the page

This commit is contained in:
filipriec
2025-03-26 00:26:36 +01:00
parent 92045a4e67
commit 11214734ae
5 changed files with 42 additions and 26 deletions

View File

@@ -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);
}
}

View File

@@ -0,0 +1,7 @@
// src/tui/functions.rs
pub mod admin;
pub mod intro;
pub use admin::*;
pub use intro::*;

View File

@@ -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());
}
}

View File

@@ -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;
}

View File

@@ -1,4 +1,5 @@
// src/tui/mod.rs
pub mod terminal;
pub mod controls;
pub mod functions;