From f2a63476b34d2421162b62978928416c58212e86 Mon Sep 17 00:00:00 2001 From: filipriec Date: Mon, 14 Apr 2025 14:05:20 +0200 Subject: [PATCH] continuation of the fixes --- client/src/modes/general/navigation.rs | 8 ++++---- client/src/tui/functions/admin.rs | 6 ++++-- client/src/tui/functions/common/register.rs | 2 +- client/src/tui/functions/intro.rs | 2 +- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/client/src/modes/general/navigation.rs b/client/src/modes/general/navigation.rs index 43d75c7..a0a927e 100644 --- a/client/src/modes/general/navigation.rs +++ b/client/src/modes/general/navigation.rs @@ -83,7 +83,7 @@ pub async fn handle_navigation_event( pub fn move_up(app_state: &mut AppState, login_state: &mut LoginState, register_state: &mut RegisterState, admin_state: &mut AdminState) { if app_state.ui.focus_outside_canvas && app_state.ui.show_login || app_state.ui.show_register{ - if app_state.button_focus_index == 0 { + if app_state.focused_button_index == 0 { app_state.ui.focus_outside_canvas = false; if app_state.ui.show_login { let last_field_index = login_state.fields().len().saturating_sub(1); @@ -93,7 +93,7 @@ pub fn move_up(app_state: &mut AppState, login_state: &mut LoginState, register_ register_state.set_current_field(last_field_index); } } else { - app_state.button_focus_index = app_state.general.selected_item.saturating_sub(1); + app_state.focused_button_index = app_state.general.selected_item.saturating_sub(1); } } else if app_state.ui.show_intro { app_state.ui.intro_state.previous_option(); @@ -105,8 +105,8 @@ pub fn move_up(app_state: &mut AppState, login_state: &mut LoginState, register_ pub fn move_down(app_state: &mut AppState, admin_state: &mut AdminState) { if app_state.ui.focus_outside_canvas && app_state.ui.show_login || app_state.ui.show_register { let num_general_elements = 2; - if app_state.button_focus_index < num_general_elements - 1 { - app_state.button_focus_index += 1; + if app_state.focused_button_index < num_general_elements - 1 { + app_state.focused_button_index += 1; } } else if app_state.ui.show_intro { app_state.ui.intro_state.next_option(); diff --git a/client/src/tui/functions/admin.rs b/client/src/tui/functions/admin.rs index 6913e1e..b0de0fd 100644 --- a/client/src/tui/functions/admin.rs +++ b/client/src/tui/functions/admin.rs @@ -3,7 +3,9 @@ use crate::state::pages::admin::AdminState; pub fn handle_admin_selection(app_state: &mut AppState, admin_state: &AdminState) { 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()); + if let Some(selected_index) = admin_state.get_selected_index() { + if let Some(profile) = profiles.get(selected_index) { + app_state.selected_profile = Some(profile.name.clone()); + } } } diff --git a/client/src/tui/functions/common/register.rs b/client/src/tui/functions/common/register.rs index feb5c72..b7866e2 100644 --- a/client/src/tui/functions/common/register.rs +++ b/client/src/tui/functions/common/register.rs @@ -147,7 +147,7 @@ pub async fn back_to_main( // Reset focus state app_state.ui.focus_outside_canvas = false; - app_state.button_focus_index = 0; + app_state.focused_button_index = 0; "Returned to main menu".to_string() } diff --git a/client/src/tui/functions/intro.rs b/client/src/tui/functions/intro.rs index 195b7f5..194548b 100644 --- a/client/src/tui/functions/intro.rs +++ b/client/src/tui/functions/intro.rs @@ -21,7 +21,7 @@ pub fn handle_intro_selection(app_state: &mut AppState, index: usize) { // Add i app_state.ui.show_intro = false; app_state.ui.show_register = true; app_state.ui.focus_outside_canvas = false; - app_state.button_focus_index = 0; + app_state.focused_button_index = 0; } _ => {} }