reverted core actions in canvas

This commit is contained in:
filipriec
2025-08-20 16:33:19 +02:00
parent 4c2464ab30
commit aea2c39215
4 changed files with 206 additions and 4 deletions

View File

@@ -754,8 +754,17 @@ impl EventHandler {
if let Some(action) = config.get_common_action(key_code, modifiers) {
match action {
"save" | "force_quit" | "save_and_quit" | "revert" => {
// TODO: Replace with proper implementation
return Ok(EventOutcome::Ok("Action not implemented".to_string()));
return self
.handle_core_action(
action,
form_state,
auth_state,
login_state,
register_state,
terminal,
app_state,
)
.await;
}
_ => {}
}
@@ -800,8 +809,17 @@ impl EventHandler {
if let Some(action) = config.get_common_action(key_code, modifiers) {
match action {
"save" | "force_quit" | "save_and_quit" | "revert" => {
// TODO: Replace with proper implementation
return Ok(EventOutcome::Ok("Action not implemented".to_string()));
return self
.handle_core_action(
action,
form_state,
auth_state,
login_state,
register_state,
terminal,
app_state,
)
.await;
}
_ => {}
}
@@ -1024,6 +1042,102 @@ impl EventHandler {
Ok(None)
}
async fn handle_core_action(
&mut self,
action: &str,
form_state: &mut FormState,
auth_state: &mut AuthState,
login_state: &mut LoginState,
register_state: &mut RegisterState,
terminal: &mut TerminalCore,
app_state: &mut AppState,
) -> Result<EventOutcome> {
match action {
"save" => {
if app_state.ui.show_login {
let message = crate::tui::functions::common::login::save(
auth_state,
login_state,
&mut self.auth_client,
app_state,
)
.await?;
Ok(EventOutcome::Ok(message))
} else {
let save_outcome = crate::tui::functions::common::form::save(
app_state,
form_state,
&mut self.grpc_client,
)
.await?;
let message = match save_outcome {
SaveOutcome::NoChange => "No changes to save.".to_string(),
SaveOutcome::UpdatedExisting => "Entry updated.".to_string(),
SaveOutcome::CreatedNew(_) => "New entry created.".to_string(),
};
Ok(EventOutcome::DataSaved(save_outcome, message))
}
}
"force_quit" => {
terminal.cleanup()?;
Ok(EventOutcome::Exit(
"Force exiting without saving.".to_string(),
))
}
"save_and_quit" => {
let message = if app_state.ui.show_login {
crate::tui::functions::common::login::save(
auth_state,
login_state,
&mut self.auth_client,
app_state,
)
.await?
} else {
let save_outcome = crate::tui::functions::common::form::save(
app_state,
form_state,
&mut self.grpc_client,
)
.await?;
match save_outcome {
SaveOutcome::NoChange => "No changes to save.".to_string(),
SaveOutcome::UpdatedExisting => "Entry updated.".to_string(),
SaveOutcome::CreatedNew(_) => "New entry created.".to_string(),
}
};
terminal.cleanup()?;
Ok(EventOutcome::Exit(format!(
"{}. Exiting application.",
message
)))
}
"revert" => {
let message = if app_state.ui.show_login {
crate::tui::functions::common::login::revert(login_state, app_state)
.await
} else if app_state.ui.show_register {
crate::tui::functions::common::register::revert(
register_state,
app_state,
)
.await
} else {
crate::tui::functions::common::form::revert(
form_state,
&mut self.grpc_client,
)
.await?
};
Ok(EventOutcome::Ok(message))
}
_ => Ok(EventOutcome::Ok(format!(
"Core action not handled: {}",
action
))),
}
}
fn is_mode_transition_action(action: &str) -> bool {
matches!(action,
"exit" |