switcher, have bugs
This commit is contained in:
@@ -1,15 +1,18 @@
|
|||||||
// src/modes/canvas/common.rs
|
// src/modes/canvas/common.rs
|
||||||
|
|
||||||
use crate::tui::terminal::core::TerminalCore;
|
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::state::state::AppState;
|
||||||
use crate::services::grpc_client::GrpcClient;
|
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(
|
pub async fn handle_core_action(
|
||||||
action: &str,
|
action: &str,
|
||||||
form_state: &mut FormState,
|
form_state: &mut FormState,
|
||||||
|
auth_state: &mut AuthState,
|
||||||
grpc_client: &mut GrpcClient,
|
grpc_client: &mut GrpcClient,
|
||||||
terminal: &mut TerminalCore,
|
terminal: &mut TerminalCore,
|
||||||
app_state: &mut AppState,
|
app_state: &mut AppState,
|
||||||
@@ -18,38 +21,52 @@ pub async fn handle_core_action(
|
|||||||
) -> Result<(bool, String), Box<dyn std::error::Error>> {
|
) -> Result<(bool, String), Box<dyn std::error::Error>> {
|
||||||
match action {
|
match action {
|
||||||
"save" => {
|
"save" => {
|
||||||
let message = save(
|
if app_state.ui.show_login {
|
||||||
form_state,
|
let message = login_save(auth_state, grpc_client).await?;
|
||||||
grpc_client,
|
Ok((false, message))
|
||||||
&mut app_state.ui.is_saved,
|
} else {
|
||||||
current_position,
|
let message = form_save(
|
||||||
total_count,
|
form_state,
|
||||||
).await?;
|
grpc_client,
|
||||||
Ok((false, message))
|
&mut app_state.ui.is_saved,
|
||||||
|
current_position,
|
||||||
|
total_count,
|
||||||
|
).await?;
|
||||||
|
Ok((false, message))
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"force_quit" => {
|
"force_quit" => {
|
||||||
terminal.cleanup()?;
|
terminal.cleanup()?;
|
||||||
Ok((true, "Force exiting without saving.".to_string()))
|
Ok((true, "Force exiting without saving.".to_string()))
|
||||||
},
|
},
|
||||||
"save_and_quit" => {
|
"save_and_quit" => {
|
||||||
let message = save(
|
let message = if app_state.ui.show_login {
|
||||||
form_state,
|
login_save(auth_state, grpc_client).await?
|
||||||
grpc_client,
|
} else {
|
||||||
&mut app_state.ui.is_saved,
|
form_save(
|
||||||
current_position,
|
form_state,
|
||||||
total_count,
|
grpc_client,
|
||||||
).await?;
|
&mut app_state.ui.is_saved,
|
||||||
|
current_position,
|
||||||
|
total_count,
|
||||||
|
).await?
|
||||||
|
};
|
||||||
terminal.cleanup()?;
|
terminal.cleanup()?;
|
||||||
Ok((true, format!("{}. Exiting application.", message)))
|
Ok((true, format!("{}. Exiting application.", message)))
|
||||||
},
|
},
|
||||||
"revert" => {
|
"revert" => {
|
||||||
let message = revert(
|
if app_state.ui.show_login {
|
||||||
form_state,
|
let message = cancel(auth_state).await;
|
||||||
grpc_client,
|
Ok((false, message))
|
||||||
current_position,
|
} else {
|
||||||
total_count,
|
let message = revert(
|
||||||
).await?;
|
form_state,
|
||||||
Ok((false, message))
|
grpc_client,
|
||||||
|
current_position,
|
||||||
|
total_count,
|
||||||
|
).await?;
|
||||||
|
Ok((false, message))
|
||||||
|
}
|
||||||
},
|
},
|
||||||
_ => Ok((false, format!("Core action not handled: {}", action))),
|
_ => Ok((false, format!("Core action not handled: {}", action))),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
// src/tui/functions/common.rs
|
// src/tui/functions/common.rs
|
||||||
pub mod commands;
|
pub mod commands;
|
||||||
pub mod form;
|
pub mod form;
|
||||||
|
pub mod login;
|
||||||
|
|
||||||
pub use commands::*;
|
pub use commands::*;
|
||||||
pub use form::*;
|
pub use form::*;
|
||||||
|
pub use login::*;
|
||||||
|
|||||||
21
client/src/tui/functions/common/login.rs
Normal file
21
client/src/tui/functions/common/login.rs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
// src/tui/functions/common/login.rs
|
||||||
|
|
||||||
|
use crate::state::pages::auth::AuthState;
|
||||||
|
use crate::services::grpc_client::GrpcClient;
|
||||||
|
|
||||||
|
/// Shared logic for login operations
|
||||||
|
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".to_string())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Shared logic for login cancellation
|
||||||
|
pub async fn cancel(
|
||||||
|
auth_state: &mut AuthState,
|
||||||
|
) -> String {
|
||||||
|
auth_state.clear_fields();
|
||||||
|
"Login cancelled".to_string()
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user