fixing more errors, last to go

This commit is contained in:
filipriec
2025-04-07 22:46:00 +02:00
parent 10e9c3ead0
commit d7d7fd614b
7 changed files with 40 additions and 37 deletions

View File

@@ -14,7 +14,6 @@ pub async fn handle_edit_event(
auth_state: &mut AuthState,
ideal_cursor_column: &mut usize,
command_message: &mut String,
is_saved: &mut bool,
current_position: &mut u64,
total_count: u64,
grpc_client: &mut GrpcClient,
@@ -42,7 +41,6 @@ pub async fn handle_edit_event(
action,
auth_state, // Concrete AuthState
grpc_client,
is_saved,
current_position,
total_count
).await
@@ -51,7 +49,6 @@ pub async fn handle_edit_event(
action,
form_state, // Concrete FormState
grpc_client,
is_saved,
current_position,
total_count
).await
@@ -68,7 +65,6 @@ pub async fn handle_edit_event(
auth_state, // Full access to AuthState fields
ideal_cursor_column,
grpc_client,
is_saved,
current_position,
total_count
).await
@@ -79,7 +75,6 @@ pub async fn handle_edit_event(
form_state, // Full access to FormState fields
ideal_cursor_column,
grpc_client,
is_saved,
current_position,
total_count
).await
@@ -95,7 +90,6 @@ pub async fn handle_edit_event(
auth_state,
ideal_cursor_column,
grpc_client,
is_saved,
current_position,
total_count
).await
@@ -106,7 +100,6 @@ pub async fn handle_edit_event(
form_state,
ideal_cursor_column,
grpc_client,
is_saved,
current_position,
total_count
).await

View File

@@ -1,22 +1,26 @@
// src/tui/controls/commands.rs
// src/modes/common/commands.rs
use crate::tui::terminal::core::TerminalCore;
use crate::state::state::AppState;
use crate::state::pages::{form::FormState, auth::AuthState};
use crate::state::canvas_state::CanvasState;
pub struct CommandHandler {
pub is_saved: bool,
}
pub struct CommandHandler;
impl CommandHandler {
pub fn new() -> Self {
Self { is_saved: false }
Self
}
pub async fn handle_command(
&mut self,
action: &str,
terminal: &mut TerminalCore,
app_state: &AppState,
form_state: &FormState,
auth_state: &AuthState,
) -> Result<(bool, String), Box<dyn std::error::Error>> {
match action {
"quit" => self.handle_quit(terminal).await,
"quit" => self.handle_quit(terminal, app_state, form_state, auth_state).await,
"force_quit" => self.handle_force_quit(terminal).await,
"save_and_quit" => self.handle_save_quit(terminal).await,
_ => Ok((false, format!("Unknown command: {}", action))),
@@ -26,8 +30,18 @@ impl CommandHandler {
async fn handle_quit(
&self,
terminal: &mut TerminalCore,
app_state: &AppState,
form_state: &FormState,
auth_state: &AuthState,
) -> Result<(bool, String), Box<dyn std::error::Error>> {
if self.is_saved {
// Use actual unsaved changes state instead of is_saved flag
let has_unsaved = if app_state.ui.show_login {
auth_state.has_unsaved_changes()
} else {
form_state.has_unsaved_changes
};
if !has_unsaved {
terminal.cleanup()?;
Ok((true, "Exiting.".into()))
} else {
@@ -47,7 +61,6 @@ impl CommandHandler {
&mut self,
terminal: &mut TerminalCore,
) -> Result<(bool, String), Box<dyn std::error::Error>> {
self.is_saved = true;
terminal.cleanup()?;
Ok((true, "State saved. Exiting.".into()))
}

View File

@@ -7,6 +7,7 @@ use crate::state::pages::form::FormState;
use crate::state::pages::auth::AuthState;
use crate::state::canvas_state::CanvasState;
use crate::tui::functions::{intro, admin};
use crate::modes::handlers::event::EventOutcome;
pub async fn handle_navigation_event(
key: KeyEvent,
@@ -17,51 +18,51 @@ pub async fn handle_navigation_event(
command_mode: &mut bool,
command_input: &mut String,
command_message: &mut String,
) -> Result<(bool, String), Box<dyn std::error::Error>> {
) -> Result<EventOutcome, Box<dyn std::error::Error>> {
if let Some(action) = config.get_general_action(key.code, key.modifiers) {
match action {
"move_up" => {
move_up(app_state, auth_state);
return Ok((false, String::new()));
return Ok(EventOutcome::Ok(String::new()));
}
"move_down" => {
move_down(app_state);
return Ok((false, String::new()));
return Ok(EventOutcome::Ok(String::new()));
}
"next_option" => {
next_option(app_state); // Intro has 2 options
return Ok((false, String::new()));
next_option(app_state);
return Ok(EventOutcome::Ok(String::new()));
}
"previous_option" => {
previous_option(app_state);
return Ok((false, String::new()));
return Ok(EventOutcome::Ok(String::new()));
}
"select" => {
select(app_state);
return Ok((false, "Selected".to_string()));
return Ok(EventOutcome::Ok("Selected".to_string()));
}
"toggle_sidebar" => {
toggle_sidebar(app_state);
return Ok((false, format!("Sidebar {}",
return Ok(EventOutcome::Ok(format!("Sidebar {}",
if app_state.ui.show_sidebar { "shown" } else { "hidden" }
)));
}
"next_field" => {
next_field(form_state);
return Ok((false, String::new()));
return Ok(EventOutcome::Ok(String::new()));
}
"prev_field" => {
prev_field(form_state);
return Ok((false, String::new()));
return Ok(EventOutcome::Ok(String::new()));
}
"enter_command_mode" => {
handle_enter_command_mode(command_mode, command_input, command_message);
return Ok((false, String::new()));
return Ok(EventOutcome::Ok(String::new()));
}
_ => {}
}
}
Ok((false, String::new()))
Ok(EventOutcome::Ok(String::new()))
}
pub fn move_up(app_state: &mut AppState, auth_state: &mut AuthState) {

View File

@@ -164,7 +164,7 @@ impl EventHandler {
}
}
let message = read_only::handle_read_only_event(
let (_should_exit, message) = read_only::handle_read_only_event(
app_state,
key,
config,