fixing more errors, last to go
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
use crate::services::grpc_client::GrpcClient;
|
use crate::services::grpc_client::GrpcClient;
|
||||||
use crate::state::canvas_state::CanvasState;
|
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 crate::tui::functions::common::form::{revert, save};
|
||||||
use crossterm::event::{KeyCode, KeyEvent};
|
use crossterm::event::{KeyCode, KeyEvent};
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
@@ -11,7 +11,6 @@ pub async fn execute_common_action<S: CanvasState + Any>(
|
|||||||
action: &str,
|
action: &str,
|
||||||
state: &mut S,
|
state: &mut S,
|
||||||
grpc_client: &mut GrpcClient,
|
grpc_client: &mut GrpcClient,
|
||||||
is_saved: &mut bool,
|
|
||||||
current_position: &mut u64,
|
current_position: &mut u64,
|
||||||
total_count: u64,
|
total_count: u64,
|
||||||
) -> Result<String, Box<dyn std::error::Error>> {
|
) -> Result<String, Box<dyn std::error::Error>> {
|
||||||
@@ -25,14 +24,15 @@ pub async fn execute_common_action<S: CanvasState + Any>(
|
|||||||
{
|
{
|
||||||
match action {
|
match action {
|
||||||
"save" => {
|
"save" => {
|
||||||
save(
|
let outcome = save(
|
||||||
form_state,
|
form_state,
|
||||||
grpc_client,
|
grpc_client,
|
||||||
is_saved,
|
|
||||||
current_position,
|
current_position,
|
||||||
total_count,
|
total_count,
|
||||||
)
|
)
|
||||||
.await
|
.await?;
|
||||||
|
let message = format!("Save successful: {:?}", outcome); // Simple message for now
|
||||||
|
Ok(message)
|
||||||
}
|
}
|
||||||
"revert" => {
|
"revert" => {
|
||||||
revert(
|
revert(
|
||||||
@@ -62,7 +62,6 @@ pub async fn execute_edit_action<S: CanvasState>(
|
|||||||
state: &mut S,
|
state: &mut S,
|
||||||
ideal_cursor_column: &mut usize,
|
ideal_cursor_column: &mut usize,
|
||||||
grpc_client: &mut GrpcClient,
|
grpc_client: &mut GrpcClient,
|
||||||
is_saved: &mut bool,
|
|
||||||
current_position: &mut u64,
|
current_position: &mut u64,
|
||||||
total_count: u64,
|
total_count: u64,
|
||||||
) -> Result<String, Box<dyn std::error::Error>> {
|
) -> Result<String, Box<dyn std::error::Error>> {
|
||||||
|
|||||||
@@ -77,7 +77,6 @@ pub async fn execute_edit_action<S: CanvasState>(
|
|||||||
state: &mut S,
|
state: &mut S,
|
||||||
ideal_cursor_column: &mut usize,
|
ideal_cursor_column: &mut usize,
|
||||||
grpc_client: &mut GrpcClient,
|
grpc_client: &mut GrpcClient,
|
||||||
is_saved: &mut bool,
|
|
||||||
current_position: &mut u64,
|
current_position: &mut u64,
|
||||||
total_count: u64,
|
total_count: u64,
|
||||||
) -> Result<String, Box<dyn std::error::Error>> {
|
) -> Result<String, Box<dyn std::error::Error>> {
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ pub async fn handle_edit_event(
|
|||||||
auth_state: &mut AuthState,
|
auth_state: &mut AuthState,
|
||||||
ideal_cursor_column: &mut usize,
|
ideal_cursor_column: &mut usize,
|
||||||
command_message: &mut String,
|
command_message: &mut String,
|
||||||
is_saved: &mut bool,
|
|
||||||
current_position: &mut u64,
|
current_position: &mut u64,
|
||||||
total_count: u64,
|
total_count: u64,
|
||||||
grpc_client: &mut GrpcClient,
|
grpc_client: &mut GrpcClient,
|
||||||
@@ -42,7 +41,6 @@ pub async fn handle_edit_event(
|
|||||||
action,
|
action,
|
||||||
auth_state, // Concrete AuthState
|
auth_state, // Concrete AuthState
|
||||||
grpc_client,
|
grpc_client,
|
||||||
is_saved,
|
|
||||||
current_position,
|
current_position,
|
||||||
total_count
|
total_count
|
||||||
).await
|
).await
|
||||||
@@ -51,7 +49,6 @@ pub async fn handle_edit_event(
|
|||||||
action,
|
action,
|
||||||
form_state, // Concrete FormState
|
form_state, // Concrete FormState
|
||||||
grpc_client,
|
grpc_client,
|
||||||
is_saved,
|
|
||||||
current_position,
|
current_position,
|
||||||
total_count
|
total_count
|
||||||
).await
|
).await
|
||||||
@@ -68,7 +65,6 @@ pub async fn handle_edit_event(
|
|||||||
auth_state, // Full access to AuthState fields
|
auth_state, // Full access to AuthState fields
|
||||||
ideal_cursor_column,
|
ideal_cursor_column,
|
||||||
grpc_client,
|
grpc_client,
|
||||||
is_saved,
|
|
||||||
current_position,
|
current_position,
|
||||||
total_count
|
total_count
|
||||||
).await
|
).await
|
||||||
@@ -79,7 +75,6 @@ pub async fn handle_edit_event(
|
|||||||
form_state, // Full access to FormState fields
|
form_state, // Full access to FormState fields
|
||||||
ideal_cursor_column,
|
ideal_cursor_column,
|
||||||
grpc_client,
|
grpc_client,
|
||||||
is_saved,
|
|
||||||
current_position,
|
current_position,
|
||||||
total_count
|
total_count
|
||||||
).await
|
).await
|
||||||
@@ -95,7 +90,6 @@ pub async fn handle_edit_event(
|
|||||||
auth_state,
|
auth_state,
|
||||||
ideal_cursor_column,
|
ideal_cursor_column,
|
||||||
grpc_client,
|
grpc_client,
|
||||||
is_saved,
|
|
||||||
current_position,
|
current_position,
|
||||||
total_count
|
total_count
|
||||||
).await
|
).await
|
||||||
@@ -106,7 +100,6 @@ pub async fn handle_edit_event(
|
|||||||
form_state,
|
form_state,
|
||||||
ideal_cursor_column,
|
ideal_cursor_column,
|
||||||
grpc_client,
|
grpc_client,
|
||||||
is_saved,
|
|
||||||
current_position,
|
current_position,
|
||||||
total_count
|
total_count
|
||||||
).await
|
).await
|
||||||
|
|||||||
@@ -1,22 +1,26 @@
|
|||||||
// src/tui/controls/commands.rs
|
// src/modes/common/commands.rs
|
||||||
use crate::tui::terminal::core::TerminalCore;
|
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 struct CommandHandler;
|
||||||
pub is_saved: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl CommandHandler {
|
impl CommandHandler {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self { is_saved: false }
|
Self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn handle_command(
|
pub async fn handle_command(
|
||||||
&mut self,
|
&mut self,
|
||||||
action: &str,
|
action: &str,
|
||||||
terminal: &mut TerminalCore,
|
terminal: &mut TerminalCore,
|
||||||
|
app_state: &AppState,
|
||||||
|
form_state: &FormState,
|
||||||
|
auth_state: &AuthState,
|
||||||
) -> Result<(bool, String), Box<dyn std::error::Error>> {
|
) -> Result<(bool, String), Box<dyn std::error::Error>> {
|
||||||
match action {
|
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,
|
"force_quit" => self.handle_force_quit(terminal).await,
|
||||||
"save_and_quit" => self.handle_save_quit(terminal).await,
|
"save_and_quit" => self.handle_save_quit(terminal).await,
|
||||||
_ => Ok((false, format!("Unknown command: {}", action))),
|
_ => Ok((false, format!("Unknown command: {}", action))),
|
||||||
@@ -26,8 +30,18 @@ impl CommandHandler {
|
|||||||
async fn handle_quit(
|
async fn handle_quit(
|
||||||
&self,
|
&self,
|
||||||
terminal: &mut TerminalCore,
|
terminal: &mut TerminalCore,
|
||||||
|
app_state: &AppState,
|
||||||
|
form_state: &FormState,
|
||||||
|
auth_state: &AuthState,
|
||||||
) -> Result<(bool, String), Box<dyn std::error::Error>> {
|
) -> 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()?;
|
terminal.cleanup()?;
|
||||||
Ok((true, "Exiting.".into()))
|
Ok((true, "Exiting.".into()))
|
||||||
} else {
|
} else {
|
||||||
@@ -47,7 +61,6 @@ impl CommandHandler {
|
|||||||
&mut self,
|
&mut self,
|
||||||
terminal: &mut TerminalCore,
|
terminal: &mut TerminalCore,
|
||||||
) -> Result<(bool, String), Box<dyn std::error::Error>> {
|
) -> Result<(bool, String), Box<dyn std::error::Error>> {
|
||||||
self.is_saved = true;
|
|
||||||
terminal.cleanup()?;
|
terminal.cleanup()?;
|
||||||
Ok((true, "State saved. Exiting.".into()))
|
Ok((true, "State saved. Exiting.".into()))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ 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::tui::functions::{intro, admin};
|
||||||
|
use crate::modes::handlers::event::EventOutcome;
|
||||||
|
|
||||||
pub async fn handle_navigation_event(
|
pub async fn handle_navigation_event(
|
||||||
key: KeyEvent,
|
key: KeyEvent,
|
||||||
@@ -17,51 +18,51 @@ pub async fn handle_navigation_event(
|
|||||||
command_mode: &mut bool,
|
command_mode: &mut bool,
|
||||||
command_input: &mut String,
|
command_input: &mut String,
|
||||||
command_message: &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) {
|
if let Some(action) = config.get_general_action(key.code, key.modifiers) {
|
||||||
match action {
|
match action {
|
||||||
"move_up" => {
|
"move_up" => {
|
||||||
move_up(app_state, auth_state);
|
move_up(app_state, auth_state);
|
||||||
return Ok((false, String::new()));
|
return Ok(EventOutcome::Ok(String::new()));
|
||||||
}
|
}
|
||||||
"move_down" => {
|
"move_down" => {
|
||||||
move_down(app_state);
|
move_down(app_state);
|
||||||
return Ok((false, String::new()));
|
return Ok(EventOutcome::Ok(String::new()));
|
||||||
}
|
}
|
||||||
"next_option" => {
|
"next_option" => {
|
||||||
next_option(app_state); // Intro has 2 options
|
next_option(app_state);
|
||||||
return Ok((false, String::new()));
|
return Ok(EventOutcome::Ok(String::new()));
|
||||||
}
|
}
|
||||||
"previous_option" => {
|
"previous_option" => {
|
||||||
previous_option(app_state);
|
previous_option(app_state);
|
||||||
return Ok((false, String::new()));
|
return Ok(EventOutcome::Ok(String::new()));
|
||||||
}
|
}
|
||||||
"select" => {
|
"select" => {
|
||||||
select(app_state);
|
select(app_state);
|
||||||
return Ok((false, "Selected".to_string()));
|
return Ok(EventOutcome::Ok("Selected".to_string()));
|
||||||
}
|
}
|
||||||
"toggle_sidebar" => {
|
"toggle_sidebar" => {
|
||||||
toggle_sidebar(app_state);
|
toggle_sidebar(app_state);
|
||||||
return Ok((false, format!("Sidebar {}",
|
return Ok(EventOutcome::Ok(format!("Sidebar {}",
|
||||||
if app_state.ui.show_sidebar { "shown" } else { "hidden" }
|
if app_state.ui.show_sidebar { "shown" } else { "hidden" }
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
"next_field" => {
|
"next_field" => {
|
||||||
next_field(form_state);
|
next_field(form_state);
|
||||||
return Ok((false, String::new()));
|
return Ok(EventOutcome::Ok(String::new()));
|
||||||
}
|
}
|
||||||
"prev_field" => {
|
"prev_field" => {
|
||||||
prev_field(form_state);
|
prev_field(form_state);
|
||||||
return Ok((false, String::new()));
|
return Ok(EventOutcome::Ok(String::new()));
|
||||||
}
|
}
|
||||||
"enter_command_mode" => {
|
"enter_command_mode" => {
|
||||||
handle_enter_command_mode(command_mode, command_input, command_message);
|
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) {
|
pub fn move_up(app_state: &mut AppState, auth_state: &mut AuthState) {
|
||||||
|
|||||||
@@ -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,
|
app_state,
|
||||||
key,
|
key,
|
||||||
config,
|
config,
|
||||||
|
|||||||
@@ -15,7 +15,6 @@ pub struct DialogState {
|
|||||||
|
|
||||||
pub struct UiState {
|
pub struct UiState {
|
||||||
pub show_sidebar: bool,
|
pub show_sidebar: bool,
|
||||||
pub is_saved: bool,
|
|
||||||
pub show_intro: bool,
|
pub show_intro: bool,
|
||||||
pub show_admin: bool,
|
pub show_admin: bool,
|
||||||
pub show_form: bool,
|
pub show_form: bool,
|
||||||
@@ -134,7 +133,6 @@ impl Default for UiState {
|
|||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
show_sidebar: true,
|
show_sidebar: true,
|
||||||
is_saved: false,
|
|
||||||
show_intro: true,
|
show_intro: true,
|
||||||
show_admin: false,
|
show_admin: false,
|
||||||
show_form: false,
|
show_form: false,
|
||||||
|
|||||||
Reference in New Issue
Block a user