edit mode is like a readonly mode

This commit is contained in:
filipriec
2025-03-31 23:56:58 +02:00
parent ca75c90ee9
commit d577ff6715
3 changed files with 32 additions and 15 deletions

View File

@@ -4,5 +4,5 @@ pub mod form;
pub mod login;
pub use commands::*;
pub use form::{revert, save as form_save};
pub use login::{cancel, save as login_save};
pub use form::{revert as form_revert, save as form_save};
pub use login::{revert as login_revert, save as login_save};

View File

@@ -2,7 +2,10 @@
use crate::services::auth::AuthClient;
use crate::state::pages::auth::AuthState;
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(
auth_state: &mut AuthState,
auth_client: &mut AuthClient,
@@ -11,35 +14,49 @@ pub async fn save(
let identifier = auth_state.username.clone();
let password = auth_state.password.clone();
// Call the gRPC login method
match auth_client.login(identifier, password).await {
Ok(response) => {
// Store authentication details on success
auth_state.auth_token = Some(response.access_token);
auth_state.user_id = Some(response.user_id);
auth_state.role = Some(response.role);
auth_state.error_message = None;
// Update app state to show main interface
auth_state.set_has_unsaved_changes(false); // Mark as "saved"
// Update app state to transition from login to the main form view
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())
}
Err(e) => {
// Store error message on failure
let error_message = format!("Login failed: {}", e);
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,
app_state: &mut AppState,
) -> String {
// Clear the input fields
auth_state.username.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_intro = true;
"Login canceled".to_string()
app_state.ui.show_intro = true; // Assuming Intro is the screen before login
"Login reverted".to_string()
}