fixing more errors, last to go
This commit is contained in:
@@ -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()))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user