router2, needs bug fixes3
This commit is contained in:
@@ -6,11 +6,10 @@ use crate::ui::handlers::context::DialogPurpose;
|
|||||||
use crate::state::app::state::AppState;
|
use crate::state::app::state::AppState;
|
||||||
use crate::buffer::AppView;
|
use crate::buffer::AppView;
|
||||||
use crate::buffer::state::BufferState;
|
use crate::buffer::state::BufferState;
|
||||||
use crate::state::pages::auth::{LoginState, RegisterState};
|
|
||||||
use crate::state::pages::admin::AdminState;
|
|
||||||
use crate::modes::handlers::event::EventOutcome;
|
use crate::modes::handlers::event::EventOutcome;
|
||||||
use crate::tui::functions::common::{login, register};
|
use crate::tui::functions::common::{login, register};
|
||||||
use crate::tui::functions::common::add_table::handle_delete_selected_columns;
|
use crate::tui::functions::common::add_table::handle_delete_selected_columns;
|
||||||
|
use crate::pages::routing::{Router, Page};
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
|
|
||||||
/// Handles key events specifically when a dialog is active.
|
/// Handles key events specifically when a dialog is active.
|
||||||
@@ -20,10 +19,8 @@ pub async fn handle_dialog_event(
|
|||||||
event: &Event,
|
event: &Event,
|
||||||
config: &Config,
|
config: &Config,
|
||||||
app_state: &mut AppState,
|
app_state: &mut AppState,
|
||||||
login_state: &mut LoginState,
|
|
||||||
register_state: &mut RegisterState,
|
|
||||||
buffer_state: &mut BufferState,
|
buffer_state: &mut BufferState,
|
||||||
admin_state: &mut AdminState,
|
router: &mut Router,
|
||||||
) -> Option<Result<EventOutcome>> {
|
) -> Option<Result<EventOutcome>> {
|
||||||
if let Event::Key(key) = event {
|
if let Event::Key(key) = event {
|
||||||
// Always allow Esc to dismiss
|
// Always allow Esc to dismiss
|
||||||
@@ -56,100 +53,131 @@ pub async fn handle_dialog_event(
|
|||||||
Some(p) => p,
|
Some(p) => p,
|
||||||
None => {
|
None => {
|
||||||
app_state.hide_dialog();
|
app_state.hide_dialog();
|
||||||
return Some(Ok(EventOutcome::Ok("Internal Error: Dialog context lost".to_string())));
|
return Some(Ok(EventOutcome::Ok(
|
||||||
|
"Internal Error: Dialog context lost".to_string(),
|
||||||
|
)));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle Dialog Actions Directly Here
|
// Handle Dialog Actions Directly Here
|
||||||
match purpose {
|
match purpose {
|
||||||
DialogPurpose::LoginSuccess => {
|
DialogPurpose::LoginSuccess => match selected_index {
|
||||||
match selected_index {
|
0 => {
|
||||||
0 => { // "Menu" button selected
|
// "Menu" button selected
|
||||||
app_state.hide_dialog();
|
app_state.hide_dialog();
|
||||||
let message = login::back_to_main(login_state, app_state, buffer_state).await;
|
if let Page::Login(state) = &mut router.current {
|
||||||
|
let message =
|
||||||
|
login::back_to_main(state, app_state, buffer_state).await;
|
||||||
return Some(Ok(EventOutcome::Ok(message)));
|
return Some(Ok(EventOutcome::Ok(message)));
|
||||||
}
|
}
|
||||||
1 => {
|
return Some(Ok(EventOutcome::Ok(
|
||||||
app_state.hide_dialog();
|
"Login state not active".to_string(),
|
||||||
return Some(Ok(EventOutcome::Ok("Exiting dialog".to_string())));
|
)));
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
app_state.hide_dialog();
|
|
||||||
return Some(Ok(EventOutcome::Ok("Unknown dialog button selected".to_string())));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
1 => {
|
||||||
DialogPurpose::LoginFailed => {
|
app_state.hide_dialog();
|
||||||
match selected_index {
|
return Some(Ok(EventOutcome::Ok("Exiting dialog".to_string())));
|
||||||
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())));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
_ => {
|
||||||
DialogPurpose::RegisterSuccess => { // Add this arm
|
app_state.hide_dialog();
|
||||||
match selected_index {
|
return Some(Ok(EventOutcome::Ok(
|
||||||
0 => { // "OK" button for RegisterSuccess
|
"Unknown dialog button selected".to_string(),
|
||||||
app_state.hide_dialog();
|
)));
|
||||||
let message = register::back_to_login(register_state, app_state, buffer_state).await;
|
}
|
||||||
|
},
|
||||||
|
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(),
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
DialogPurpose::RegisterSuccess => match selected_index {
|
||||||
|
0 => {
|
||||||
|
// "OK" button for RegisterSuccess
|
||||||
|
app_state.hide_dialog();
|
||||||
|
if let Page::Register(state) = &mut router.current {
|
||||||
|
let message =
|
||||||
|
register::back_to_login(state, app_state, buffer_state)
|
||||||
|
.await;
|
||||||
return Some(Ok(EventOutcome::Ok(message)));
|
return Some(Ok(EventOutcome::Ok(message)));
|
||||||
}
|
}
|
||||||
_ => { // Default for RegisterSuccess
|
return Some(Ok(EventOutcome::Ok(
|
||||||
app_state.hide_dialog();
|
"Register state not active".to_string(),
|
||||||
return Some(Ok(EventOutcome::Ok("Unknown dialog button selected".to_string())));
|
)));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
_ => {
|
||||||
DialogPurpose::RegisterFailed => { // Add this arm
|
app_state.hide_dialog();
|
||||||
match selected_index {
|
return Some(Ok(EventOutcome::Ok(
|
||||||
0 => { // "OK" button for RegisterFailed
|
"Unknown dialog button selected".to_string(),
|
||||||
app_state.hide_dialog(); // Just dismiss
|
)));
|
||||||
return Some(Ok(EventOutcome::Ok("Register failed dialog dismissed".to_string())));
|
|
||||||
}
|
|
||||||
_ => { // Default for RegisterFailed
|
|
||||||
app_state.hide_dialog();
|
|
||||||
return Some(Ok(EventOutcome::Ok("Unknown dialog button selected".to_string())));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
DialogPurpose::ConfirmDeleteColumns => {
|
DialogPurpose::RegisterFailed => match selected_index {
|
||||||
match selected_index {
|
0 => {
|
||||||
0 => { // "Confirm" button selected
|
// "OK" button for RegisterFailed
|
||||||
let outcome_message = handle_delete_selected_columns(&mut admin_state.add_table_state);
|
app_state.hide_dialog(); // Just dismiss
|
||||||
|
return Some(Ok(EventOutcome::Ok(
|
||||||
|
"Register failed dialog dismissed".to_string(),
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
app_state.hide_dialog();
|
||||||
|
return Some(Ok(EventOutcome::Ok(
|
||||||
|
"Unknown dialog button selected".to_string(),
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
},
|
||||||
|
DialogPurpose::ConfirmDeleteColumns => match selected_index {
|
||||||
|
0 => {
|
||||||
|
// "Confirm" button selected
|
||||||
|
if let Page::Admin(state) = &mut router.current {
|
||||||
|
let outcome_message =
|
||||||
|
handle_delete_selected_columns(&mut state.add_table_state);
|
||||||
app_state.hide_dialog();
|
app_state.hide_dialog();
|
||||||
return Some(Ok(EventOutcome::Ok(outcome_message)));
|
return Some(Ok(EventOutcome::Ok(outcome_message)));
|
||||||
}
|
}
|
||||||
1 => { // "Cancel" button selected
|
return Some(Ok(EventOutcome::Ok(
|
||||||
app_state.hide_dialog();
|
"Admin state not active".to_string(),
|
||||||
return Some(Ok(EventOutcome::Ok("Deletion cancelled.".to_string())));
|
)));
|
||||||
}
|
|
||||||
_ => { /* Handle unexpected index */ }
|
|
||||||
}
|
}
|
||||||
}
|
1 => {
|
||||||
DialogPurpose::SaveTableSuccess => {
|
// "Cancel" button selected
|
||||||
match selected_index {
|
app_state.hide_dialog();
|
||||||
0 => { // "OK" button selected
|
return Some(Ok(EventOutcome::Ok("Deletion cancelled.".to_string())));
|
||||||
app_state.hide_dialog();
|
|
||||||
buffer_state.update_history(AppView::Admin); // Navigate back
|
|
||||||
return Some(Ok(EventOutcome::Ok("Save success dialog dismissed.".to_string())));
|
|
||||||
}
|
|
||||||
_ => { /* Handle unexpected index */ }
|
|
||||||
}
|
}
|
||||||
}
|
_ => { /* Handle unexpected index */ }
|
||||||
DialogPurpose::SaveLogicSuccess => {
|
},
|
||||||
match selected_index {
|
DialogPurpose::SaveTableSuccess => match selected_index {
|
||||||
0 => { // "OK" button selected
|
0 => {
|
||||||
app_state.hide_dialog();
|
// "OK" button selected
|
||||||
buffer_state.update_history(AppView::Admin);
|
app_state.hide_dialog();
|
||||||
return Some(Ok(EventOutcome::Ok("Save success dialog dismissed.".to_string())));
|
buffer_state.update_history(AppView::Admin); // Navigate back
|
||||||
}
|
return Some(Ok(EventOutcome::Ok(
|
||||||
_ => { /* Handle unexpected index */ }
|
"Save success dialog dismissed.".to_string(),
|
||||||
|
)));
|
||||||
}
|
}
|
||||||
}
|
_ => { /* Handle unexpected index */ }
|
||||||
|
},
|
||||||
|
DialogPurpose::SaveLogicSuccess => match selected_index {
|
||||||
|
0 => {
|
||||||
|
// "OK" button selected
|
||||||
|
app_state.hide_dialog();
|
||||||
|
buffer_state.update_history(AppView::Admin);
|
||||||
|
return Some(Ok(EventOutcome::Ok(
|
||||||
|
"Save success dialog dismissed.".to_string(),
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
_ => { /* Handle unexpected index */ }
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {} // Ignore other general actions when dialog is shown
|
_ => {} // Ignore other general actions when dialog is shown
|
||||||
|
|||||||
@@ -232,12 +232,9 @@ pub async fn run_ui() -> Result<()> {
|
|||||||
&mut terminal,
|
&mut terminal,
|
||||||
&mut command_handler,
|
&mut command_handler,
|
||||||
&mut auth_state,
|
&mut auth_state,
|
||||||
&mut login_state,
|
|
||||||
&mut register_state,
|
|
||||||
&mut intro_state,
|
|
||||||
&mut admin_state,
|
|
||||||
&mut buffer_state,
|
&mut buffer_state,
|
||||||
&mut app_state,
|
&mut app_state,
|
||||||
|
&mut router,
|
||||||
).await;
|
).await;
|
||||||
let mut should_exit = false;
|
let mut should_exit = false;
|
||||||
match event_outcome_result {
|
match event_outcome_result {
|
||||||
|
|||||||
Reference in New Issue
Block a user