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

@@ -10,6 +10,9 @@ use crate::state::pages::form::FormState;
use crate::state::pages::auth::AuthState;
use crate::state::canvas_state::CanvasState;
use crate::ui::handlers::rat_state::UiStateHandler;
use crate::ui::handlers::context::UiContext;
use crate::tui::functions::{intro, admin};
use crate::tui::functions::common::login;
use crate::modes::{
common::command_mode,
canvas::{edit, read_only, common_mode},
@@ -21,10 +24,10 @@ use crate::tui::functions::common::form::SaveOutcome;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum EventOutcome {
Ok(String), // Normal operation, display message
Exit(String), // Signal app exit, display message
DataSaved(SaveOutcome, String), // Data save attempted, include outcome and message
// Add other outcomes like QuitRequested, SaveAndQuitRequested later if needed
Ok(String),
Exit(String),
DataSaved(SaveOutcome, String),
ButtonSelected { context: UiContext, index: usize },
}
pub struct EventHandler {
@@ -81,7 +84,7 @@ impl EventHandler {
match current_mode {
AppMode::General => {
return navigation::handle_navigation_event(
let nav_outcome = navigation::handle_navigation_event(
key,
config,
form_state,
@@ -91,6 +94,42 @@ impl EventHandler {
&mut self.command_input,
&mut self.command_message,
).await;
match nav_outcome {
Ok(EventOutcome::ButtonSelected { context, index }) => {
let mut message = String::from("Selected"); // Default message
match context {
UiContext::Intro => {
intro::handle_intro_selection(app_state, index); // Pass index
message = format!("Intro Option {} selected", index);
}
UiContext::Login => {
message = match index {
0 => login::save(auth_state, &mut self.auth_client, app_state).await?,
1 => {
let msg = login::revert(auth_state, app_state).await;
// Optional: Add navigation logic here if revert should change screen
// app_state.ui.show_login = false;
// app_state.ui.show_intro = true;
msg
}
_ => "Invalid Login Option".to_string(),
};
}
UiContext::Admin => {
// Assuming handle_admin_selection uses app_state.general.selected_item
admin::handle_admin_selection(app_state);
message = format!("Admin Option {} selected", index);
}
UiContext::Dialog => {
// Add specific dialog handling logic here
message = format!("Dialog Button {} selected", index);
app_state.hide_dialog(); // Example action
}
}
return Ok(EventOutcome::Ok(message)); // Return Ok with message
}
other => return other, // Pass through Ok, Err, DataSaved directly
}
},
AppMode::ReadOnly => {