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

@@ -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
auth_state.current_field = 0;
auth_state.return_selected = false;
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
}
// 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 'down' from functions/login"))
},
_ => Err("Unknown login action".into())
}
// Reset cursor position for the field
auth_state.current_cursor_pos = auth_state.get_current_input().len();
Ok("".to_string())
}
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())
}