we compiled centralized system for select

This commit is contained in:
filipriec
2025-04-10 12:13:04 +02:00
parent a8eef8107b
commit 8c7a0a1ec0
7 changed files with 79 additions and 21 deletions

View File

@@ -6,7 +6,7 @@ use crate::state::state::AppState;
use crate::state::pages::form::FormState;
use crate::state::pages::auth::AuthState;
use crate::state::canvas_state::CanvasState;
use crate::tui::functions::{intro, admin};
use crate::ui::handlers::context::UiContext;
use crate::modes::handlers::event::EventOutcome;
pub async fn handle_navigation_event(
@@ -37,10 +37,6 @@ pub async fn handle_navigation_event(
previous_option(app_state);
return Ok(EventOutcome::Ok(String::new()));
}
"select" => {
select(app_state);
return Ok(EventOutcome::Ok("Selected".to_string()));
}
"toggle_sidebar" => {
toggle_sidebar(app_state);
return Ok(EventOutcome::Ok(format!("Sidebar {}",
@@ -59,6 +55,21 @@ pub async fn handle_navigation_event(
handle_enter_command_mode(command_mode, command_input, command_message);
return Ok(EventOutcome::Ok(String::new()));
}
"select" => {
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)
} else if app_state.ui.show_admin {
(UiContext::Admin, app_state.general.selected_item)
} 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 });
}
_ => {}
}
}
@@ -134,14 +145,6 @@ pub fn previous_option(app_state: &mut AppState) {
}
}
pub fn select(app_state: &mut AppState) {
if app_state.ui.show_intro {
intro::handle_intro_selection(app_state);
} else if app_state.ui.show_admin {
admin::handle_admin_selection(app_state);
}
}
pub fn toggle_sidebar(app_state: &mut AppState) {
app_state.ui.show_sidebar = !app_state.ui.show_sidebar;
}