dialog login functionality

This commit is contained in:
filipriec
2025-04-10 15:36:43 +02:00
parent 3ed8764087
commit 6b241304fb
5 changed files with 39 additions and 25 deletions

View File

@@ -3,7 +3,8 @@
use crossterm::event::{Event, KeyCode};
use crate::config::binds::config::Config;
use crate::state::state::AppState;
use crate::modes::handlers::event::EventOutcome; // Use EventOutcome from event handler
use crate::modes::handlers::event::EventOutcome;
use crate::ui::handlers::context::DialogPurpose;
/// Handles key events specifically when a dialog is active.
/// Returns Some(Result<EventOutcome, Error>) if the event was handled (consumed),
@@ -41,22 +42,16 @@ pub async fn handle_dialog_event(
}
"select" => {
let selected_index = app_state.ui.dialog.dialog_active_button_index;
let selected_label = app_state.get_active_dialog_button_label().unwrap_or("").to_string();
let mut message = format!("Dialog '{}' selected", selected_label);
let purpose = match app_state.ui.dialog.purpose {
Some(p) => p,
None => {
app_state.hide_dialog();
return Some(Ok(EventOutcome::Ok("Internal Error: Dialog context lost".to_string())));
}
};
// --- Add specific actions based on button index or label ---
if selected_label.eq_ignore_ascii_case("menu") {
app_state.ui.show_login = false;
app_state.ui.show_intro = true;
// focus_outside_canvas is handled by hide_dialog
message = "Returning to menu".to_string();
} else if selected_label.eq_ignore_ascii_case("exit") {
app_state.hide_dialog();
return Some(Ok(EventOutcome::Exit("Exiting via dialog".to_string())));
}
// --- End specific actions ---
app_state.hide_dialog(); // Hide dialog after processing selection
return Some(Ok(EventOutcome::Ok(message))); // Consume event
app_state.hide_dialog();
return Some(Ok(EventOutcome::DialogAction { purpose, selected_index }));
}
_ => {} // Ignore other general actions when dialog is shown
}