Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7f5b671084 | ||
|
|
3ccf71ed0f |
@@ -1,15 +1,18 @@
|
||||
// src/modes/canvas/common.rs
|
||||
|
||||
use crate::tui::terminal::core::TerminalCore;
|
||||
use crate::state::pages::form::FormState;
|
||||
use crate::state::pages::{form::FormState, auth::AuthState};
|
||||
use crate::state::state::AppState;
|
||||
use crate::services::grpc_client::GrpcClient;
|
||||
use crate::tui::functions::common::form::{save, revert};
|
||||
use crate::tui::functions::common::{
|
||||
form::{save as form_save, revert},
|
||||
login::{save as login_save, cancel}
|
||||
};
|
||||
|
||||
/// Main handler for common core actions
|
||||
pub async fn handle_core_action(
|
||||
action: &str,
|
||||
form_state: &mut FormState,
|
||||
auth_state: &mut AuthState,
|
||||
grpc_client: &mut GrpcClient,
|
||||
terminal: &mut TerminalCore,
|
||||
app_state: &mut AppState,
|
||||
@@ -18,38 +21,52 @@ pub async fn handle_core_action(
|
||||
) -> Result<(bool, String), Box<dyn std::error::Error>> {
|
||||
match action {
|
||||
"save" => {
|
||||
let message = save(
|
||||
form_state,
|
||||
grpc_client,
|
||||
&mut app_state.ui.is_saved,
|
||||
current_position,
|
||||
total_count,
|
||||
).await?;
|
||||
Ok((false, message))
|
||||
if app_state.ui.show_login {
|
||||
let message = login_save(auth_state, grpc_client).await?;
|
||||
Ok((false, message))
|
||||
} else {
|
||||
let message = form_save(
|
||||
form_state,
|
||||
grpc_client,
|
||||
&mut app_state.ui.is_saved,
|
||||
current_position,
|
||||
total_count,
|
||||
).await?;
|
||||
Ok((false, message))
|
||||
}
|
||||
},
|
||||
"force_quit" => {
|
||||
terminal.cleanup()?;
|
||||
Ok((true, "Force exiting without saving.".to_string()))
|
||||
},
|
||||
"save_and_quit" => {
|
||||
let message = save(
|
||||
form_state,
|
||||
grpc_client,
|
||||
&mut app_state.ui.is_saved,
|
||||
current_position,
|
||||
total_count,
|
||||
).await?;
|
||||
let message = if app_state.ui.show_login {
|
||||
login_save(auth_state, grpc_client).await?
|
||||
} else {
|
||||
form_save(
|
||||
form_state,
|
||||
grpc_client,
|
||||
&mut app_state.ui.is_saved,
|
||||
current_position,
|
||||
total_count,
|
||||
).await?
|
||||
};
|
||||
terminal.cleanup()?;
|
||||
Ok((true, format!("{}. Exiting application.", message)))
|
||||
},
|
||||
"revert" => {
|
||||
let message = revert(
|
||||
form_state,
|
||||
grpc_client,
|
||||
current_position,
|
||||
total_count,
|
||||
).await?;
|
||||
Ok((false, message))
|
||||
if app_state.ui.show_login {
|
||||
let message = cancel(auth_state).await;
|
||||
Ok((false, message))
|
||||
} else {
|
||||
let message = revert(
|
||||
form_state,
|
||||
grpc_client,
|
||||
current_position,
|
||||
total_count,
|
||||
).await?;
|
||||
Ok((false, message))
|
||||
}
|
||||
},
|
||||
_ => Ok((false, format!("Core action not handled: {}", action))),
|
||||
}
|
||||
|
||||
@@ -131,6 +131,7 @@ impl EventHandler {
|
||||
return common::handle_core_action(
|
||||
action,
|
||||
form_state,
|
||||
&mut self.auth_state,
|
||||
grpc_client,
|
||||
terminal,
|
||||
app_state,
|
||||
@@ -191,6 +192,7 @@ impl EventHandler {
|
||||
return common::handle_core_action(
|
||||
action,
|
||||
form_state,
|
||||
&mut self.auth_state,
|
||||
grpc_client,
|
||||
terminal,
|
||||
app_state,
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
// src/tui/functions/common.rs
|
||||
pub mod commands;
|
||||
pub mod form;
|
||||
pub mod login;
|
||||
|
||||
pub use commands::*;
|
||||
pub use form::*;
|
||||
pub use form::{revert, save as form_save};
|
||||
pub use login::{cancel, save as login_save};
|
||||
|
||||
18
client/src/tui/functions/common/login.rs
Normal file
18
client/src/tui/functions/common/login.rs
Normal file
@@ -0,0 +1,18 @@
|
||||
// src/tui/functions/common/login.rs
|
||||
|
||||
use crate::state::pages::auth::AuthState;
|
||||
use crate::services::grpc_client::GrpcClient;
|
||||
|
||||
pub async fn save(
|
||||
auth_state: &mut AuthState,
|
||||
grpc_client: &mut GrpcClient,
|
||||
) -> Result<String, Box<dyn std::error::Error>> {
|
||||
// Implement your login-specific save logic here
|
||||
Ok("Login credentials saved - not implemented yet".to_string())
|
||||
}
|
||||
|
||||
pub async fn cancel(
|
||||
auth_state: &mut AuthState,
|
||||
) -> String {
|
||||
"Login credentials canceled - not implemented yet".to_string()
|
||||
}
|
||||
Reference in New Issue
Block a user