we successfully compiled and wen from auth state to login state and auth state
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
use crate::services::auth::AuthClient;
|
||||
use crate::state::pages::auth::AuthState;
|
||||
use crate::state::pages::auth::LoginState;
|
||||
use crate::state::state::AppState;
|
||||
use crate::state::canvas_state::CanvasState;
|
||||
use crate::ui::handlers::context::DialogPurpose;
|
||||
@@ -10,14 +11,15 @@ use crate::ui::handlers::context::DialogPurpose;
|
||||
/// Updates AuthState and AppState on success or failure.
|
||||
pub async fn save(
|
||||
auth_state: &mut AuthState,
|
||||
login_state: &mut LoginState,
|
||||
auth_client: &mut AuthClient,
|
||||
app_state: &mut AppState,
|
||||
) -> Result<String, Box<dyn std::error::Error>> {
|
||||
let identifier = auth_state.username.clone();
|
||||
let password = auth_state.password.clone();
|
||||
let identifier = login_state.username.clone();
|
||||
let password = login_state.password.clone();
|
||||
|
||||
// Clear previous error/dialog state before attempting
|
||||
auth_state.error_message = None;
|
||||
login_state.error_message = None;
|
||||
// Use the helper to ensure dialog is hidden and cleared properly
|
||||
app_state.hide_dialog();
|
||||
|
||||
@@ -29,7 +31,7 @@ pub async fn save(
|
||||
auth_state.user_id = Some(response.user_id.clone());
|
||||
auth_state.role = Some(response.role.clone());
|
||||
auth_state.decoded_username = Some(response.username.clone());
|
||||
auth_state.set_has_unsaved_changes(false);
|
||||
login_state.set_has_unsaved_changes(false);
|
||||
|
||||
let success_message = format!(
|
||||
"Login Successful!\n\n\
|
||||
@@ -60,13 +62,8 @@ pub async fn save(
|
||||
vec!["OK".to_string()],
|
||||
DialogPurpose::LoginFailed,
|
||||
);
|
||||
// REMOVE these lines:
|
||||
// app_state.ui.dialog.dialog_title = "Login Failed".to_string();
|
||||
// app_state.ui.dialog.dialog_message = error_message.clone();
|
||||
// app_state.ui.dialog.dialog_show = true;
|
||||
// app_state.ui.dialog.dialog_button_active = true;
|
||||
|
||||
auth_state.set_has_unsaved_changes(true);
|
||||
login_state.set_has_unsaved_changes(true);
|
||||
|
||||
Ok(format!("Login failed: {}", error_message))
|
||||
}
|
||||
@@ -75,27 +72,27 @@ pub async fn save(
|
||||
|
||||
/// Reverts the login form fields to empty and returns to the previous screen (Intro).
|
||||
pub async fn revert(
|
||||
auth_state: &mut AuthState,
|
||||
login_state: &mut LoginState,
|
||||
app_state: &mut AppState,
|
||||
) -> String {
|
||||
// Clear the input fields
|
||||
auth_state.username.clear();
|
||||
auth_state.password.clear();
|
||||
auth_state.error_message = None;
|
||||
auth_state.set_has_unsaved_changes(false);
|
||||
login_state.username.clear();
|
||||
login_state.password.clear();
|
||||
login_state.error_message = None;
|
||||
login_state.set_has_unsaved_changes(false);
|
||||
|
||||
"Login reverted".to_string()
|
||||
}
|
||||
|
||||
pub async fn back_to_main(
|
||||
auth_state: &mut AuthState,
|
||||
login_state: &mut LoginState,
|
||||
app_state: &mut AppState,
|
||||
) -> String {
|
||||
// Clear the input fields
|
||||
auth_state.username.clear();
|
||||
auth_state.password.clear();
|
||||
auth_state.error_message = None;
|
||||
auth_state.set_has_unsaved_changes(false);
|
||||
login_state.username.clear();
|
||||
login_state.password.clear();
|
||||
login_state.error_message = None;
|
||||
login_state.set_has_unsaved_changes(false);
|
||||
|
||||
// Ensure dialog is hidden if revert is called
|
||||
app_state.hide_dialog(); // Uncomment if needed
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
// src/tui/functions/login.rs
|
||||
use crate::state::pages::auth::AuthState;
|
||||
|
||||
pub async fn handle_action(
|
||||
action: &str,
|
||||
auth_state: &mut AuthState,
|
||||
ideal_cursor_column: &mut usize,
|
||||
) -> Result<String, Box<dyn std::error::Error>> {
|
||||
pub async fn handle_action(action: &str,) -> Result<String, Box<dyn std::error::Error>> {
|
||||
match action {
|
||||
"previous_entry" => {
|
||||
Ok("Previous entry at tui/functions/login.rs not implemented".into())
|
||||
|
||||
Reference in New Issue
Block a user