working, split config where functions for each page are defined for this page, if the functions are not general for each page. Huge update, works for tui/functions/form and fui/functions/login. Working, time to move to other things

This commit is contained in:
filipriec
2025-03-30 15:46:49 +02:00
parent 13d4db6bdc
commit e36b1817bc
3 changed files with 61 additions and 29 deletions

View File

@@ -4,6 +4,7 @@
use crossterm::event::{KeyEvent};
use crate::config::binds::config::Config;
use crate::state::pages::form::FormState;
use crate::state::pages::auth::AuthState;
use crate::config::binds::key_sequences::KeySequenceTracker;
use crate::tui::terminal::grpc_client::GrpcClient;
@@ -19,6 +20,7 @@ pub async fn handle_read_only_event(
key: KeyEvent,
config: &Config,
form_state: &mut FormState,
auth_state: &mut AuthState,
key_sequence_tracker: &mut KeySequenceTracker,
current_position: &mut u64,
total_count: u64,
@@ -62,6 +64,12 @@ pub async fn handle_read_only_event(
total_count,
ideal_cursor_column,
).await?
} else if (action == "move_up" || action == "move_down") && app_state.ui.show_login {
crate::tui::functions::login::handle_action(
action,
auth_state,
ideal_cursor_column,
).await?
} else {
execute_action(
action,

View File

@@ -8,6 +8,7 @@ use crate::tui::terminal::{
use crate::tui::controls::commands::CommandHandler;
use crate::config::binds::config::Config;
use crate::state::pages::form::FormState;
use crate::state::pages::auth::AuthState;
use crate::ui::handlers::rat_state::UiStateHandler;
use crate::modes::{
common::{command_mode},
@@ -25,6 +26,7 @@ pub struct EventHandler {
pub edit_mode_cooldown: bool,
pub ideal_cursor_column: usize,
pub key_sequence_tracker: KeySequenceTracker,
pub auth_state: AuthState,
}
impl EventHandler {
@@ -37,6 +39,7 @@ impl EventHandler {
edit_mode_cooldown: false,
ideal_cursor_column: 0,
key_sequence_tracker: KeySequenceTracker::new(800),
auth_state: AuthState::new(),
}
}
@@ -145,6 +148,7 @@ impl EventHandler {
key,
config,
form_state,
&mut self.auth_state,
&mut self.key_sequence_tracker,
current_position,
total_count,

View File

@@ -2,37 +2,57 @@
use crate::state::pages::auth::AuthState;
use crate::state::canvas_state::CanvasState;
pub async fn handle_move_up(
pub async fn handle_action(
action: &str,
auth_state: &mut AuthState,
ideal_cursor_column: &mut usize,
) -> Result<String, Box<dyn std::error::Error>> {
if auth_state.current_field > 0 {
auth_state.current_field -= 1;
} else {
// If at first field (username), cycle to button selection
match action {
"move_up" => {
if auth_state.return_selected {
// Coming from return button to fields
auth_state.return_selected = false;
auth_state.current_field = 1; // Focus on password field
} else if auth_state.current_field == 1 {
// Moving from password to username/email
auth_state.current_field = 0;
} else if auth_state.current_field == 0 {
// Wrap around to buttons
auth_state.return_selected = false; // Select Login button
}
// Update cursor position when in a field
if !auth_state.return_selected {
let current_input = auth_state.get_current_input();
let max_cursor_pos = current_input.len();
auth_state.current_cursor_pos = (*ideal_cursor_column).min(max_cursor_pos);
}
Ok(format!("Navigation 'up' from functions/login"))
},
"move_down" => {
if auth_state.return_selected {
// Coming from return button to fields
auth_state.return_selected = false;
auth_state.current_field = 0; // Focus on username field
} else if auth_state.current_field == 0 {
// Moving from username/email to password
auth_state.current_field = 1;
} else if auth_state.current_field == 1 {
// Moving from password to buttons
auth_state.return_selected = false; // Select Login button
}
// Reset cursor position for the field
auth_state.current_cursor_pos = auth_state.get_current_input().len();
Ok("".to_string())
// Update cursor position when in a field
if !auth_state.return_selected {
let current_input = auth_state.get_current_input();
let max_cursor_pos = current_input.len();
auth_state.current_cursor_pos = (*ideal_cursor_column).min(max_cursor_pos);
}
pub async fn handle_move_down(
auth_state: &mut AuthState,
) -> Result<String, Box<dyn std::error::Error>> {
if auth_state.current_field < 1 {
// Moving down from username to password
auth_state.current_field += 1;
// Reset cursor position for the new field
auth_state.current_cursor_pos = auth_state.get_current_input().len();
} else {
// Moving from password field to button selection
auth_state.return_selected = false;
}
Ok("".to_string())
Ok(format!("Navigation 'down' from functions/login"))
},
_ => Err("Unknown login action".into())
}
}