compiled
This commit is contained in:
@@ -3,8 +3,11 @@
|
||||
use crossterm::event::{Event, KeyCode};
|
||||
use crate::config::binds::config::Config;
|
||||
use crate::state::state::AppState;
|
||||
use crate::modes::handlers::event::EventOutcome;
|
||||
use crate::ui::handlers::context::DialogPurpose;
|
||||
use crate::state::pages::auth::AuthState;
|
||||
use crate::services::auth::AuthClient;
|
||||
use crate::modes::handlers::event::EventOutcome;
|
||||
use crate::tui::functions::common::login;
|
||||
|
||||
/// Handles key events specifically when a dialog is active.
|
||||
/// Returns Some(Result<EventOutcome, Error>) if the event was handled (consumed),
|
||||
@@ -13,6 +16,8 @@ pub async fn handle_dialog_event(
|
||||
event: &Event,
|
||||
config: &Config,
|
||||
app_state: &mut AppState,
|
||||
auth_state: &mut AuthState,
|
||||
auth_client: &mut AuthClient,
|
||||
) -> Option<Result<EventOutcome, Box<dyn std::error::Error>>> {
|
||||
if let Event::Key(key) = event {
|
||||
// Always allow Esc to dismiss
|
||||
@@ -38,7 +43,6 @@ pub async fn handle_dialog_event(
|
||||
app_state.ui.dialog.dialog_active_button_index -= 1;
|
||||
}
|
||||
return Some(Ok(EventOutcome::Ok(String::new())));
|
||||
|
||||
}
|
||||
"select" => {
|
||||
let selected_index = app_state.ui.dialog.dialog_active_button_index;
|
||||
@@ -50,8 +54,40 @@ pub async fn handle_dialog_event(
|
||||
}
|
||||
};
|
||||
|
||||
app_state.hide_dialog();
|
||||
return Some(Ok(EventOutcome::DialogAction { purpose, selected_index }));
|
||||
// Handle Dialog Actions Directly Here
|
||||
match purpose {
|
||||
DialogPurpose::LoginSuccess => {
|
||||
match selected_index {
|
||||
0 => { // "Menu" button selected
|
||||
// Hide dialog before calling action that might change state further
|
||||
app_state.hide_dialog();
|
||||
let message = login::back_to_main(auth_state, app_state).await;
|
||||
return Some(Ok(EventOutcome::Ok(message)));
|
||||
}
|
||||
1 => { // "Exit" button selected
|
||||
app_state.hide_dialog();
|
||||
return Some(Ok(EventOutcome::Exit("Exiting via dialog".to_string())));
|
||||
}
|
||||
_ => {
|
||||
app_state.hide_dialog();
|
||||
return Some(Ok(EventOutcome::Ok("Unknown dialog button selected".to_string())));
|
||||
}
|
||||
}
|
||||
}
|
||||
DialogPurpose::LoginFailed => {
|
||||
match selected_index {
|
||||
0 => { // "OK" button selected
|
||||
app_state.hide_dialog();
|
||||
return Some(Ok(EventOutcome::Ok("Login failed dialog dismissed".to_string())));
|
||||
}
|
||||
_ => {
|
||||
app_state.hide_dialog();
|
||||
return Some(Ok(EventOutcome::Ok("Unknown dialog button selected".to_string())));
|
||||
}
|
||||
}
|
||||
}
|
||||
// Add cases for other DialogPurpose variants here if needed
|
||||
}
|
||||
}
|
||||
_ => {} // Ignore other general actions when dialog is shown
|
||||
}
|
||||
@@ -63,4 +99,3 @@ pub async fn handle_dialog_event(
|
||||
Some(Ok(EventOutcome::Ok(String::new())))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user