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:
@@ -4,6 +4,7 @@
|
|||||||
use crossterm::event::{KeyEvent};
|
use crossterm::event::{KeyEvent};
|
||||||
use crate::config::binds::config::Config;
|
use crate::config::binds::config::Config;
|
||||||
use crate::state::pages::form::FormState;
|
use crate::state::pages::form::FormState;
|
||||||
|
use crate::state::pages::auth::AuthState;
|
||||||
use crate::config::binds::key_sequences::KeySequenceTracker;
|
use crate::config::binds::key_sequences::KeySequenceTracker;
|
||||||
use crate::tui::terminal::grpc_client::GrpcClient;
|
use crate::tui::terminal::grpc_client::GrpcClient;
|
||||||
|
|
||||||
@@ -19,6 +20,7 @@ pub async fn handle_read_only_event(
|
|||||||
key: KeyEvent,
|
key: KeyEvent,
|
||||||
config: &Config,
|
config: &Config,
|
||||||
form_state: &mut FormState,
|
form_state: &mut FormState,
|
||||||
|
auth_state: &mut AuthState,
|
||||||
key_sequence_tracker: &mut KeySequenceTracker,
|
key_sequence_tracker: &mut KeySequenceTracker,
|
||||||
current_position: &mut u64,
|
current_position: &mut u64,
|
||||||
total_count: u64,
|
total_count: u64,
|
||||||
@@ -62,6 +64,12 @@ pub async fn handle_read_only_event(
|
|||||||
total_count,
|
total_count,
|
||||||
ideal_cursor_column,
|
ideal_cursor_column,
|
||||||
).await?
|
).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 {
|
} else {
|
||||||
execute_action(
|
execute_action(
|
||||||
action,
|
action,
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ use crate::tui::terminal::{
|
|||||||
use crate::tui::controls::commands::CommandHandler;
|
use crate::tui::controls::commands::CommandHandler;
|
||||||
use crate::config::binds::config::Config;
|
use crate::config::binds::config::Config;
|
||||||
use crate::state::pages::form::FormState;
|
use crate::state::pages::form::FormState;
|
||||||
|
use crate::state::pages::auth::AuthState;
|
||||||
use crate::ui::handlers::rat_state::UiStateHandler;
|
use crate::ui::handlers::rat_state::UiStateHandler;
|
||||||
use crate::modes::{
|
use crate::modes::{
|
||||||
common::{command_mode},
|
common::{command_mode},
|
||||||
@@ -25,6 +26,7 @@ pub struct EventHandler {
|
|||||||
pub edit_mode_cooldown: bool,
|
pub edit_mode_cooldown: bool,
|
||||||
pub ideal_cursor_column: usize,
|
pub ideal_cursor_column: usize,
|
||||||
pub key_sequence_tracker: KeySequenceTracker,
|
pub key_sequence_tracker: KeySequenceTracker,
|
||||||
|
pub auth_state: AuthState,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl EventHandler {
|
impl EventHandler {
|
||||||
@@ -37,6 +39,7 @@ impl EventHandler {
|
|||||||
edit_mode_cooldown: false,
|
edit_mode_cooldown: false,
|
||||||
ideal_cursor_column: 0,
|
ideal_cursor_column: 0,
|
||||||
key_sequence_tracker: KeySequenceTracker::new(800),
|
key_sequence_tracker: KeySequenceTracker::new(800),
|
||||||
|
auth_state: AuthState::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,6 +148,7 @@ impl EventHandler {
|
|||||||
key,
|
key,
|
||||||
config,
|
config,
|
||||||
form_state,
|
form_state,
|
||||||
|
&mut self.auth_state,
|
||||||
&mut self.key_sequence_tracker,
|
&mut self.key_sequence_tracker,
|
||||||
current_position,
|
current_position,
|
||||||
total_count,
|
total_count,
|
||||||
|
|||||||
@@ -2,37 +2,57 @@
|
|||||||
use crate::state::pages::auth::AuthState;
|
use crate::state::pages::auth::AuthState;
|
||||||
use crate::state::canvas_state::CanvasState;
|
use crate::state::canvas_state::CanvasState;
|
||||||
|
|
||||||
pub async fn handle_move_up(
|
pub async fn handle_action(
|
||||||
|
action: &str,
|
||||||
auth_state: &mut AuthState,
|
auth_state: &mut AuthState,
|
||||||
|
ideal_cursor_column: &mut usize,
|
||||||
) -> Result<String, Box<dyn std::error::Error>> {
|
) -> Result<String, Box<dyn std::error::Error>> {
|
||||||
if auth_state.current_field > 0 {
|
match action {
|
||||||
auth_state.current_field -= 1;
|
"move_up" => {
|
||||||
} else {
|
if auth_state.return_selected {
|
||||||
// If at first field (username), cycle to button selection
|
// 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;
|
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.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
|
// Update cursor position when in a field
|
||||||
auth_state.current_cursor_pos = auth_state.get_current_input().len();
|
if !auth_state.return_selected {
|
||||||
|
let current_input = auth_state.get_current_input();
|
||||||
Ok("".to_string())
|
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(
|
Ok(format!("Navigation 'down' from functions/login"))
|
||||||
auth_state: &mut AuthState,
|
},
|
||||||
) -> Result<String, Box<dyn std::error::Error>> {
|
_ => Err("Unknown login action".into())
|
||||||
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())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user