we compiled centralized system for select
This commit is contained in:
@@ -57,7 +57,9 @@ pub async fn handle_edit_event(
|
|||||||
EventOutcome::Ok(msg) => msg,
|
EventOutcome::Ok(msg) => msg,
|
||||||
EventOutcome::Exit(msg) => format!("Exit requested: {}", msg), // Or handle differently
|
EventOutcome::Exit(msg) => format!("Exit requested: {}", msg), // Or handle differently
|
||||||
EventOutcome::DataSaved(save_outcome, msg) => format!("Data saved ({:?}): {}", save_outcome, msg),
|
EventOutcome::DataSaved(save_outcome, msg) => format!("Data saved ({:?}): {}", save_outcome, msg),
|
||||||
// Add other EventOutcome variants if necessary
|
EventOutcome::ButtonSelected { context, index } => {
|
||||||
|
"Unexpected action in edit mode".to_string()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}?;
|
}?;
|
||||||
return Ok(message);
|
return Ok(message);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ use crate::state::state::AppState;
|
|||||||
use crate::state::pages::form::FormState;
|
use crate::state::pages::form::FormState;
|
||||||
use crate::state::pages::auth::AuthState;
|
use crate::state::pages::auth::AuthState;
|
||||||
use crate::state::canvas_state::CanvasState;
|
use crate::state::canvas_state::CanvasState;
|
||||||
use crate::tui::functions::{intro, admin};
|
use crate::ui::handlers::context::UiContext;
|
||||||
use crate::modes::handlers::event::EventOutcome;
|
use crate::modes::handlers::event::EventOutcome;
|
||||||
|
|
||||||
pub async fn handle_navigation_event(
|
pub async fn handle_navigation_event(
|
||||||
@@ -37,10 +37,6 @@ pub async fn handle_navigation_event(
|
|||||||
previous_option(app_state);
|
previous_option(app_state);
|
||||||
return Ok(EventOutcome::Ok(String::new()));
|
return Ok(EventOutcome::Ok(String::new()));
|
||||||
}
|
}
|
||||||
"select" => {
|
|
||||||
select(app_state);
|
|
||||||
return Ok(EventOutcome::Ok("Selected".to_string()));
|
|
||||||
}
|
|
||||||
"toggle_sidebar" => {
|
"toggle_sidebar" => {
|
||||||
toggle_sidebar(app_state);
|
toggle_sidebar(app_state);
|
||||||
return Ok(EventOutcome::Ok(format!("Sidebar {}",
|
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);
|
handle_enter_command_mode(command_mode, command_input, command_message);
|
||||||
return Ok(EventOutcome::Ok(String::new()));
|
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) {
|
pub fn toggle_sidebar(app_state: &mut AppState) {
|
||||||
app_state.ui.show_sidebar = !app_state.ui.show_sidebar;
|
app_state.ui.show_sidebar = !app_state.ui.show_sidebar;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ use crate::state::pages::form::FormState;
|
|||||||
use crate::state::pages::auth::AuthState;
|
use crate::state::pages::auth::AuthState;
|
||||||
use crate::state::canvas_state::CanvasState;
|
use crate::state::canvas_state::CanvasState;
|
||||||
use crate::ui::handlers::rat_state::UiStateHandler;
|
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::{
|
use crate::modes::{
|
||||||
common::command_mode,
|
common::command_mode,
|
||||||
canvas::{edit, read_only, common_mode},
|
canvas::{edit, read_only, common_mode},
|
||||||
@@ -21,10 +24,10 @@ use crate::tui::functions::common::form::SaveOutcome;
|
|||||||
|
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
pub enum EventOutcome {
|
pub enum EventOutcome {
|
||||||
Ok(String), // Normal operation, display message
|
Ok(String),
|
||||||
Exit(String), // Signal app exit, display message
|
Exit(String),
|
||||||
DataSaved(SaveOutcome, String), // Data save attempted, include outcome and message
|
DataSaved(SaveOutcome, String),
|
||||||
// Add other outcomes like QuitRequested, SaveAndQuitRequested later if needed
|
ButtonSelected { context: UiContext, index: usize },
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct EventHandler {
|
pub struct EventHandler {
|
||||||
@@ -81,7 +84,7 @@ impl EventHandler {
|
|||||||
|
|
||||||
match current_mode {
|
match current_mode {
|
||||||
AppMode::General => {
|
AppMode::General => {
|
||||||
return navigation::handle_navigation_event(
|
let nav_outcome = navigation::handle_navigation_event(
|
||||||
key,
|
key,
|
||||||
config,
|
config,
|
||||||
form_state,
|
form_state,
|
||||||
@@ -91,6 +94,42 @@ impl EventHandler {
|
|||||||
&mut self.command_input,
|
&mut self.command_input,
|
||||||
&mut self.command_message,
|
&mut self.command_message,
|
||||||
).await;
|
).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 => {
|
AppMode::ReadOnly => {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
use crate::state::state::AppState;
|
use crate::state::state::AppState;
|
||||||
|
|
||||||
pub fn handle_intro_selection(app_state: &mut AppState) {
|
pub fn handle_intro_selection(app_state: &mut AppState, index: usize) { // Add index parameter
|
||||||
match app_state.ui.intro_state.selected_option {
|
match index { // Use index directly
|
||||||
0 => { // Continue
|
0 => { // Continue
|
||||||
app_state.ui.show_form = true;
|
app_state.ui.show_form = true;
|
||||||
app_state.ui.show_admin = false;
|
app_state.ui.show_admin = false;
|
||||||
@@ -21,3 +21,4 @@ pub fn handle_intro_selection(app_state: &mut AppState) {
|
|||||||
}
|
}
|
||||||
app_state.ui.show_intro = false;
|
app_state.ui.show_intro = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
pub mod ui;
|
pub mod ui;
|
||||||
pub mod render;
|
pub mod render;
|
||||||
pub mod rat_state;
|
pub mod rat_state;
|
||||||
|
pub mod context;
|
||||||
|
|
||||||
pub use ui::run_ui;
|
pub use ui::run_ui;
|
||||||
pub use rat_state::*;
|
pub use rat_state::*;
|
||||||
|
pub use context::*;
|
||||||
|
|||||||
8
client/src/ui/handlers/context.rs
Normal file
8
client/src/ui/handlers/context.rs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
pub enum UiContext {
|
||||||
|
Intro,
|
||||||
|
Login,
|
||||||
|
Admin,
|
||||||
|
Dialog,
|
||||||
|
}
|
||||||
|
|
||||||
@@ -152,6 +152,9 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
}
|
}
|
||||||
// No count update needed for UpdatedExisting or NoChange
|
// No count update needed for UpdatedExisting or NoChange
|
||||||
}
|
}
|
||||||
|
EventOutcome::ButtonSelected { context, index } => {
|
||||||
|
event_handler.command_message = "Internal error: Unexpected button state".to_string();
|
||||||
|
}
|
||||||
},
|
},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
// Handle errors from handle_event, e.g., log or display
|
// Handle errors from handle_event, e.g., log or display
|
||||||
|
|||||||
Reference in New Issue
Block a user