From adcd3b37fa44194db85017d2bfb1202cba861336 Mon Sep 17 00:00:00 2001 From: filipriec Date: Mon, 14 Apr 2025 13:23:09 +0200 Subject: [PATCH] fixing this --- client/src/components/auth/login.rs | 4 ++-- client/src/components/auth/register.rs | 4 ++-- client/src/functions/modes/read_only/auth_ro.rs | 2 +- client/src/modes/general/navigation.rs | 17 ++++++++--------- client/src/modes/handlers/event.rs | 2 +- client/src/state/app/state.rs | 2 ++ client/src/tui/functions/admin.rs | 3 ++- client/src/tui/functions/common/login.rs | 2 +- client/src/tui/functions/common/register.rs | 2 +- client/src/tui/functions/intro.rs | 2 +- 10 files changed, 21 insertions(+), 19 deletions(-) diff --git a/client/src/components/auth/login.rs b/client/src/components/auth/login.rs index f2bb19a..bc90623 100644 --- a/client/src/components/auth/login.rs +++ b/client/src/components/auth/login.rs @@ -77,7 +77,7 @@ pub fn render_login( // Login Button let login_button_index = 0; let login_active = if app_state.ui.focus_outside_canvas { - app_state.general.selected_item == login_button_index + app_state.focused_button_index== login_button_index } else { false }; @@ -104,7 +104,7 @@ pub fn render_login( // Return Button let return_button_index = 1; // Assuming Return is the second general element let return_active = if app_state.ui.focus_outside_canvas { - app_state.general.selected_item == return_button_index + app_state.focused_button_index== return_button_index } else { false // Not active if focus is in canvas or other modes }; diff --git a/client/src/components/auth/register.rs b/client/src/components/auth/register.rs index af4beae..fef822d 100644 --- a/client/src/components/auth/register.rs +++ b/client/src/components/auth/register.rs @@ -92,7 +92,7 @@ pub fn render_register( // Register Button let register_button_index = 0; let register_active = if app_state.ui.focus_outside_canvas { - app_state.general.selected_item == register_button_index + app_state.focused_button_index== register_button_index } else { false }; @@ -119,7 +119,7 @@ pub fn render_register( // Return Button (logic remains similar) let return_button_index = 1; let return_active = if app_state.ui.focus_outside_canvas { - app_state.general.selected_item == return_button_index + app_state.focused_button_index== return_button_index } else { false }; diff --git a/client/src/functions/modes/read_only/auth_ro.rs b/client/src/functions/modes/read_only/auth_ro.rs index b181399..6ed2790 100644 --- a/client/src/functions/modes/read_only/auth_ro.rs +++ b/client/src/functions/modes/read_only/auth_ro.rs @@ -60,7 +60,7 @@ pub async fn execute_action( if current_field == last_field_index { // Already on the last field, move focus outside app_state.ui.focus_outside_canvas = true; - app_state.general.selected_item = 0; // Focus first general item (e.g., Login button) + app_state.focused_button_index= 0; key_sequence_tracker.reset(); Ok("Focus moved below canvas".to_string()) } else { diff --git a/client/src/modes/general/navigation.rs b/client/src/modes/general/navigation.rs index 7833c50..43d75c7 100644 --- a/client/src/modes/general/navigation.rs +++ b/client/src/modes/general/navigation.rs @@ -63,15 +63,14 @@ pub async fn handle_navigation_event( let (context, index) = if app_state.ui.show_intro { (UiContext::Intro, app_state.ui.intro_state.selected_option) } else if app_state.ui.show_login && app_state.ui.focus_outside_canvas { - (UiContext::Login, app_state.general.selected_item) + (UiContext::Login, app_state.focused_button_index) } else if app_state.ui.show_register && app_state.ui.focus_outside_canvas { - (UiContext::Register, app_state.general.selected_item) + (UiContext::Register, app_state.focused_button_index) } else if app_state.ui.show_admin { - (UiContext::Admin, app_state.general.selected_item) + (UiContext::Admin, admin_state.get_selected_index().unwrap_or(0)) } else if app_state.ui.dialog.dialog_show { (UiContext::Dialog, app_state.ui.dialog.dialog_active_button_index) } else { - // Handle cases where select is pressed but no button context applies return Ok(EventOutcome::Ok("Select (No Action)".to_string())); }; return Ok(EventOutcome::ButtonSelected { context, index }); @@ -84,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.general.selected_item == 0 { + if app_state.button_focus_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); @@ -94,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.general.selected_item = app_state.general.selected_item.saturating_sub(1); + app_state.button_focus_index = app_state.general.selected_item.saturating_sub(1); } } else if app_state.ui.show_intro { app_state.ui.intro_state.previous_option(); @@ -106,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.general.selected_item < num_general_elements - 1 { - app_state.general.selected_item += 1; + if app_state.button_focus_index < num_general_elements - 1 { + app_state.button_focus_index += 1; } } else if app_state.ui.show_intro { app_state.ui.intro_state.next_option(); @@ -132,7 +131,7 @@ pub fn previous_option(app_state: &mut AppState) { } else { let option_count = app_state.profile_tree.profiles.len(); app_state.general.current_option = if app_state.general.current_option == 0 { - option_count.saturating_sub(1) // Wrap to last option + option_count.saturating_sub(1) } else { app_state.general.current_option - 1 }; diff --git a/client/src/modes/handlers/event.rs b/client/src/modes/handlers/event.rs index 87aea2e..e4e5410 100644 --- a/client/src/modes/handlers/event.rs +++ b/client/src/modes/handlers/event.rs @@ -143,7 +143,7 @@ impl EventHandler { }; } UiContext::Admin => { - admin::handle_admin_selection(app_state); + admin::handle_admin_selection(app_state, admin_state); message = format!("Admin Option {} selected", index); } diff --git a/client/src/state/app/state.rs b/client/src/state/app/state.rs index af66ae1..c2ae1fb 100644 --- a/client/src/state/app/state.rs +++ b/client/src/state/app/state.rs @@ -35,6 +35,7 @@ pub struct AppState { pub profile_tree: ProfileTreeResponse, pub selected_profile: Option, pub current_mode: AppMode, + pub focused_button_index: usize, // UI preferences pub ui: UiState, @@ -52,6 +53,7 @@ impl AppState { profile_tree: ProfileTreeResponse::default(), selected_profile: None, current_mode: AppMode::General, + focused_button_index: 0, ui: UiState::default(), }) } diff --git a/client/src/tui/functions/admin.rs b/client/src/tui/functions/admin.rs index bc38954..6913e1e 100644 --- a/client/src/tui/functions/admin.rs +++ b/client/src/tui/functions/admin.rs @@ -1,6 +1,7 @@ use crate::state::app::state::AppState; +use crate::state::pages::admin::AdminState; -pub fn handle_admin_selection(app_state: &mut AppState) { +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()); diff --git a/client/src/tui/functions/common/login.rs b/client/src/tui/functions/common/login.rs index f207e0e..2d69c2a 100644 --- a/client/src/tui/functions/common/login.rs +++ b/client/src/tui/functions/common/login.rs @@ -103,7 +103,7 @@ pub async fn back_to_main( // Reset focus state app_state.ui.focus_outside_canvas = false; - app_state.general.selected_item = 0; + app_state.focused_button_index= 0; "Returned to main menu".to_string() } diff --git a/client/src/tui/functions/common/register.rs b/client/src/tui/functions/common/register.rs index 6913158..feb5c72 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.general.selected_item = 0; // Reset intro selection + app_state.button_focus_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 da7468f..195b7f5 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.general.selected_item = 0; + app_state.button_focus_index = 0; } _ => {} }