router4 compiled

This commit is contained in:
Priec
2025-08-22 23:27:32 +02:00
parent b9072e4d7c
commit 78bc9fc432
3 changed files with 392 additions and 407 deletions

View File

@@ -12,6 +12,7 @@ use anyhow::Result;
use crate::components::common::text_editor::TextEditor;
use crate::services::ui_service::UiService;
use tui_textarea::CursorMove;
use crate::state::pages::admin::AdminState;
use crate::pages::routing::{Router, Page};
pub type SaveLogicResultSender = mpsc::Sender<Result<String>>;
@@ -20,14 +21,15 @@ pub fn handle_add_logic_navigation(
key_event: KeyEvent,
config: &Config,
app_state: &mut AppState,
add_logic_state: &mut AddLogicState,
is_edit_mode: &mut bool,
buffer_state: &mut BufferState,
grpc_client: GrpcClient,
_save_logic_sender: SaveLogicResultSender, // Marked as unused
save_logic_sender: SaveLogicResultSender,
command_message: &mut String,
router: &mut Router,
) -> bool {
if let Page::AddLogic(add_logic_state) = &mut router.current {
// === FULLSCREEN SCRIPT EDITING - COMPLETE ISOLATION ===
if add_logic_state.current_focus == AddLogicFocus::InsideScriptContent {
// === AUTOCOMPLETE HANDLING ===
@@ -382,9 +384,9 @@ pub fn handle_add_logic_navigation(
}
AddLogicFocus::CancelButton => {
buffer_state.update_history(AppView::Admin);
router.navigate(Page::Admin(app_state.admin_state().clone()));
*command_message = "Cancelled Add Logic".to_string();
*is_edit_mode = false;
}
AddLogicFocus::InputLogicName | AddLogicFocus::InputTargetColumn | AddLogicFocus::InputDescription => {
*is_edit_mode = !*is_edit_mode;
@@ -423,6 +425,9 @@ pub fn handle_add_logic_navigation(
}
}
handled
} else {
return false; // not on AddLogic page
}
}
fn replace_autocomplete_text(

View File

@@ -3,20 +3,20 @@
use crossterm::event::{KeyEvent, KeyCode, KeyModifiers};
use crate::config::binds::config::Config;
use crate::services::grpc_client::GrpcClient;
use crate::state::{app::state::AppState, pages::auth::LoginState, pages::auth::RegisterState};
use crate::state::app::state::AppState;
use crate::modes::common::commands::CommandHandler;
use crate::tui::terminal::core::TerminalCore;
use crate::tui::functions::common::form::{save, revert};
use crate::modes::handlers::event::EventOutcome;
use crate::tui::functions::common::form::SaveOutcome;
use crate::pages::routing::{Router, Page};
use anyhow::Result;
pub async fn handle_command_event(
key: KeyEvent,
config: &Config,
app_state: &mut AppState,
login_state: &LoginState,
register_state: &RegisterState,
router: &mut Router,
command_input: &mut String,
command_message: &mut String,
grpc_client: &mut GrpcClient,
@@ -25,20 +25,19 @@ pub async fn handle_command_event(
current_position: &mut u64,
total_count: u64,
) -> Result<EventOutcome> {
// Exit command mode (via configurable keybinding)
// Exit command mode
if config.is_exit_command_mode(key.code, key.modifiers) {
command_input.clear();
*command_message = "".to_string();
return Ok(EventOutcome::Ok("Exited command mode".to_string()));
}
// Execute command (via configurable keybinding, defaults to Enter)
// Execute command
if config.is_command_execute(key.code, key.modifiers) {
return process_command(
config,
app_state,
login_state,
register_state,
router,
command_input,
command_message,
grpc_client,
@@ -46,33 +45,31 @@ pub async fn handle_command_event(
terminal,
current_position,
total_count,
).await;
)
.await;
}
// Backspace (via configurable keybinding, defaults to Backspace)
// Backspace
if config.is_command_backspace(key.code, key.modifiers) {
command_input.pop();
return Ok(EventOutcome::Ok("".to_string()));
}
// Regular character input - accept any character in command mode
// Regular character input
if let KeyCode::Char(c) = key.code {
// Accept regular or shifted characters (e.g., 'a' or 'A')
if key.modifiers.is_empty() || key.modifiers == KeyModifiers::SHIFT {
command_input.push(c);
return Ok(EventOutcome::Ok("".to_string()));
}
}
// Ignore all other keys
Ok(EventOutcome::Ok("".to_string()))
}
async fn process_command(
config: &Config,
app_state: &mut AppState,
login_state: &LoginState,
register_state: &RegisterState,
router: &mut Router,
command_input: &mut String,
command_message: &mut String,
grpc_client: &mut GrpcClient,
@@ -81,27 +78,18 @@ async fn process_command(
current_position: &mut u64,
total_count: u64,
) -> Result<EventOutcome> {
// Clone the trimmed command to avoid borrow issues
let command = command_input.trim().to_string();
if command.is_empty() {
*command_message = "Empty command".to_string();
return Ok(EventOutcome::Ok(command_message.clone()));
}
// Get the action for the command (now checks global and common bindings too)
let action = config.get_action_for_command(&command)
.unwrap_or("unknown");
let action = config.get_action_for_command(&command).unwrap_or("unknown");
match action {
"force_quit" | "save_and_quit" | "quit" => {
let (should_exit, message) = command_handler
.handle_command(
action,
terminal,
app_state,
login_state,
register_state,
)
.handle_command(action, terminal, app_state, router)
.await?;
command_input.clear();
if should_exit {
@@ -109,12 +97,9 @@ async fn process_command(
} else {
Ok(EventOutcome::Ok(message))
}
},
}
"save" => {
let outcome = save(
app_state,
grpc_client,
).await?;
let outcome = save(app_state, grpc_client).await?;
let message = match outcome {
SaveOutcome::CreatedNew(_) => "New entry created".to_string(),
SaveOutcome::UpdatedExisting => "Entry updated".to_string(),
@@ -122,15 +107,12 @@ async fn process_command(
};
command_input.clear();
Ok(EventOutcome::DataSaved(outcome, message))
},
}
"revert" => {
let message = revert(
app_state,
grpc_client,
).await?;
let message = revert(app_state, grpc_client).await?;
command_input.clear();
Ok(EventOutcome::Ok(message))
},
}
_ => {
let message = format!("Unhandled action: {}", action);
command_input.clear();

View File

@@ -369,7 +369,7 @@ impl EventHandler {
match current_mode {
AppMode::General => {
if let Page::Admin(admin_state) = &router.current {
if let Page::Admin(admin_state) = &mut router.current {
if auth_state.role.as_deref() == Some("admin") {
if admin_nav::handle_admin_navigation(
key_event,
@@ -386,25 +386,23 @@ impl EventHandler {
}
}
if let Page::AddLogic(add_logic_state) = &mut router.current {
let client_clone = self.grpc_client.clone();
let sender_clone = self.save_logic_result_sender.clone();
if add_logic_nav::handle_add_logic_navigation(
key_event,
config,
app_state,
add_logic_state,
&mut self.is_edit_mode,
buffer_state,
client_clone,
sender_clone,
&mut self.command_message,
router,
) {
return Ok(EventOutcome::Ok(
self.command_message.clone(),
));
}
}
if let Page::AddTable(add_table_state) = &mut router.current {
let client_clone = self.grpc_client.clone();
@@ -443,7 +441,7 @@ impl EventHandler {
buffer_state,
index,
);
if let Page::Admin(admin_state) = &router.current {
if let Page::Admin(admin_state) = &mut router.current {
if !app_state
.profile_tree
.profiles
@@ -457,7 +455,7 @@ impl EventHandler {
format!("Intro Option {} selected", index)
}
UiContext::Login => {
if let Page::Login(login_state) = &router.current {
if let Page::Login(login_state) = &mut router.current {
match index {
0 => login::initiate_login(
login_state,
@@ -478,7 +476,7 @@ impl EventHandler {
}
}
UiContext::Register => {
if let Page::Register(register_state) = &router.current {
if let Page::Register(register_state) = &mut router.current {
match index {
0 => register::initiate_registration(
register_state,
@@ -807,7 +805,7 @@ impl EventHandler {
) -> Result<EventOutcome> {
match action {
"save" => {
if let Page::Login(login_state) = &router.current {
if let Page::Login(login_state) = &mut router.current {
let message = crate::tui::functions::common::login::save(
auth_state,
login_state,
@@ -844,7 +842,7 @@ impl EventHandler {
))
}
"save_and_quit" => {
let message = if let Page::Login(login_state) = &router.current {
let message = if let Page::Login(login_state) = &mut router.current {
crate::tui::functions::common::login::save(
auth_state,
login_state,
@@ -873,10 +871,10 @@ impl EventHandler {
)))
}
"revert" => {
let message = if let Page::Login(login_state) = &router.current {
let message = if let Page::Login(login_state) = &mut router.current {
crate::tui::functions::common::login::revert(login_state, app_state)
.await
} else if let Page::Register(register_state) = &router.current {
} else if let Page::Register(register_state) = &mut router.current {
crate::tui::functions::common::register::revert(
register_state,
app_state,