switching of the views done

This commit is contained in:
filipriec
2025-03-31 16:23:25 +02:00
parent e2c326bf1e
commit 3d266c2ad0

View File

@@ -1,10 +1,12 @@
// src/tui/functions/common/login.rs // src/tui/functions/common/login.rs
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;
pub async fn save( pub async fn save(
auth_state: &mut AuthState, auth_state: &mut AuthState,
auth_client: &mut AuthClient, auth_client: &mut AuthClient,
app_state: &mut AppState,
) -> Result<String, Box<dyn std::error::Error>> { ) -> Result<String, Box<dyn std::error::Error>> {
let identifier = auth_state.username.clone(); let identifier = auth_state.username.clone();
let password = auth_state.password.clone(); let password = auth_state.password.clone();
@@ -15,6 +17,11 @@ pub async fn save(
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;
// Update app state to show main interface
app_state.ui.show_login = false;
app_state.ui.show_form = true;
Ok("Login successful!".to_string()) Ok("Login successful!".to_string())
} }
Err(e) => { Err(e) => {
@@ -27,9 +34,12 @@ pub async fn save(
pub async fn cancel( pub async fn cancel(
auth_state: &mut AuthState, auth_state: &mut AuthState,
app_state: &mut AppState,
) -> String { ) -> String {
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;
app_state.ui.show_login = false;
app_state.ui.show_intro = true;
"Login canceled".to_string() "Login canceled".to_string()
} }