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

@@ -2,7 +2,7 @@
use crate::services::grpc_client::GrpcClient;
use crate::state::canvas_state::CanvasState;
use crate::state::pages::form::FormState;
use crate::state::pages::{auth::AuthState, form::FormState};
use crate::tui::functions::common::form::{revert, save};
use crossterm::event::{KeyCode, KeyEvent};
use std::any::Any;
@@ -11,7 +11,6 @@ pub async fn execute_common_action<S: CanvasState + Any>(
action: &str,
state: &mut S,
grpc_client: &mut GrpcClient,
is_saved: &mut bool,
current_position: &mut u64,
total_count: u64,
) -> Result<String, Box<dyn std::error::Error>> {
@@ -25,14 +24,15 @@ pub async fn execute_common_action<S: CanvasState + Any>(
{
match action {
"save" => {
save(
let outcome = save(
form_state,
grpc_client,
is_saved,
current_position,
total_count,
)
.await
.await?;
let message = format!("Save successful: {:?}", outcome); // Simple message for now
Ok(message)
}
"revert" => {
revert(
@@ -62,7 +62,6 @@ pub async fn execute_edit_action<S: CanvasState>(
state: &mut S,
ideal_cursor_column: &mut usize,
grpc_client: &mut GrpcClient,
is_saved: &mut bool,
current_position: &mut u64,
total_count: u64,
) -> Result<String, Box<dyn std::error::Error>> {

View File

@@ -77,7 +77,6 @@ pub async fn execute_edit_action<S: CanvasState>(
state: &mut S,
ideal_cursor_column: &mut usize,
grpc_client: &mut GrpcClient,
is_saved: &mut bool,
current_position: &mut u64,
total_count: u64,
) -> Result<String, Box<dyn std::error::Error>> {

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,

View File

@@ -15,7 +15,6 @@ pub struct DialogState {
pub struct UiState {
pub show_sidebar: bool,
pub is_saved: bool,
pub show_intro: bool,
pub show_admin: bool,
pub show_form: bool,
@@ -134,7 +133,6 @@ impl Default for UiState {
fn default() -> Self {
Self {
show_sidebar: true,
is_saved: false,
show_intro: true,
show_admin: false,
show_form: false,