edit mode is like a readonly mode
This commit is contained in:
@@ -6,8 +6,8 @@ use crate::state::state::AppState;
|
|||||||
use crate::services::grpc_client::GrpcClient;
|
use crate::services::grpc_client::GrpcClient;
|
||||||
use crate::services::auth::AuthClient;
|
use crate::services::auth::AuthClient;
|
||||||
use crate::tui::functions::common::{
|
use crate::tui::functions::common::{
|
||||||
form::{save as form_save, revert},
|
form::{save as form_save, revert as form_revert},
|
||||||
login::{save as login_save, cancel}
|
login::{save as login_save, revert as login_revert}
|
||||||
};
|
};
|
||||||
|
|
||||||
pub async fn handle_core_action(
|
pub async fn handle_core_action(
|
||||||
@@ -58,10 +58,10 @@ pub async fn handle_core_action(
|
|||||||
},
|
},
|
||||||
"revert" => {
|
"revert" => {
|
||||||
if app_state.ui.show_login {
|
if app_state.ui.show_login {
|
||||||
let message = cancel(auth_state, app_state).await;
|
let message = login_revert(auth_state, app_state).await;
|
||||||
Ok((false, message))
|
Ok((false, message))
|
||||||
} else {
|
} else {
|
||||||
let message = revert(
|
let message = form_revert(
|
||||||
form_state,
|
form_state,
|
||||||
grpc_client,
|
grpc_client,
|
||||||
current_position,
|
current_position,
|
||||||
|
|||||||
@@ -4,5 +4,5 @@ pub mod form;
|
|||||||
pub mod login;
|
pub mod login;
|
||||||
|
|
||||||
pub use commands::*;
|
pub use commands::*;
|
||||||
pub use form::{revert, save as form_save};
|
pub use form::{revert as form_revert, save as form_save};
|
||||||
pub use login::{cancel, save as login_save};
|
pub use login::{revert as login_revert, save as login_save};
|
||||||
|
|||||||
@@ -2,7 +2,10 @@
|
|||||||
use crate::services::auth::AuthClient;
|
use crate::services::auth::AuthClient;
|
||||||
use crate::state::pages::auth::AuthState;
|
use crate::state::pages::auth::AuthState;
|
||||||
use crate::state::state::AppState;
|
use crate::state::state::AppState;
|
||||||
|
use crate::state::canvas_state::CanvasState;
|
||||||
|
|
||||||
|
/// Attempts to log the user in using the provided credentials via gRPC.
|
||||||
|
/// Updates AuthState and AppState on success or failure.
|
||||||
pub async fn save(
|
pub async fn save(
|
||||||
auth_state: &mut AuthState,
|
auth_state: &mut AuthState,
|
||||||
auth_client: &mut AuthClient,
|
auth_client: &mut AuthClient,
|
||||||
@@ -11,35 +14,49 @@ pub async fn save(
|
|||||||
let identifier = auth_state.username.clone();
|
let identifier = auth_state.username.clone();
|
||||||
let password = auth_state.password.clone();
|
let password = auth_state.password.clone();
|
||||||
|
|
||||||
|
// Call the gRPC login method
|
||||||
match auth_client.login(identifier, password).await {
|
match auth_client.login(identifier, password).await {
|
||||||
Ok(response) => {
|
Ok(response) => {
|
||||||
|
// Store authentication details on success
|
||||||
auth_state.auth_token = Some(response.access_token);
|
auth_state.auth_token = Some(response.access_token);
|
||||||
auth_state.user_id = Some(response.user_id);
|
auth_state.user_id = Some(response.user_id);
|
||||||
auth_state.role = Some(response.role);
|
auth_state.role = Some(response.role);
|
||||||
auth_state.error_message = None;
|
auth_state.error_message = None;
|
||||||
|
auth_state.set_has_unsaved_changes(false); // Mark as "saved"
|
||||||
// Update app state to show main interface
|
|
||||||
|
// Update app state to transition from login to the main form view
|
||||||
app_state.ui.show_login = false;
|
app_state.ui.show_login = false;
|
||||||
app_state.ui.show_form = true;
|
app_state.ui.show_form = true; // Assuming form is the next view
|
||||||
|
|
||||||
Ok("Login successful!".to_string())
|
Ok("Login successful!".to_string())
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
// Store error message on failure
|
||||||
let error_message = format!("Login failed: {}", e);
|
let error_message = format!("Login failed: {}", e);
|
||||||
auth_state.error_message = Some(error_message.clone());
|
auth_state.error_message = Some(error_message.clone());
|
||||||
Ok(error_message)
|
// Keep unsaved changes true if login fails, allowing retry/revert
|
||||||
|
auth_state.set_has_unsaved_changes(true);
|
||||||
|
Ok(error_message) // Return error message to display
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn cancel(
|
/// Reverts the login form fields to empty and returns to the previous screen (Intro).
|
||||||
|
/// This function is now named 'revert' to match the 'form' counterpart.
|
||||||
|
pub async fn revert(
|
||||||
auth_state: &mut AuthState,
|
auth_state: &mut AuthState,
|
||||||
app_state: &mut AppState,
|
app_state: &mut AppState,
|
||||||
) -> String {
|
) -> String {
|
||||||
|
// Clear the input fields
|
||||||
auth_state.username.clear();
|
auth_state.username.clear();
|
||||||
auth_state.password.clear();
|
auth_state.password.clear();
|
||||||
auth_state.error_message = None;
|
auth_state.error_message = None; // Clear any previous error
|
||||||
|
auth_state.set_has_unsaved_changes(false); // Fields are cleared, no unsaved changes
|
||||||
|
|
||||||
|
// Update app state to hide login and show the previous screen (Intro)
|
||||||
app_state.ui.show_login = false;
|
app_state.ui.show_login = false;
|
||||||
app_state.ui.show_intro = true;
|
app_state.ui.show_intro = true; // Assuming Intro is the screen before login
|
||||||
"Login canceled".to_string()
|
|
||||||
|
"Login reverted".to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user