working read only mode in login and register properly workig now

This commit is contained in:
filipriec
2025-04-11 08:50:54 +02:00
parent 14f9b254b2
commit eff46ac9bf
3 changed files with 63 additions and 13 deletions

View File

@@ -3,7 +3,7 @@
use crate::config::binds::config::Config;
use crate::config::binds::key_sequences::KeySequenceTracker;
use crate::services::grpc_client::GrpcClient;
use crate::state::canvas_state::CanvasState;
use crate::state::{canvas_state::CanvasState, pages::auth::RegisterState};
use crate::state::pages::auth::AuthState;
use crate::state::pages::form::FormState;
use crate::state::state::AppState;
@@ -16,6 +16,7 @@ pub async fn handle_read_only_event(
config: &Config,
form_state: &mut FormState,
auth_state: &mut AuthState,
register_state: &mut RegisterState,
key_sequence_tracker: &mut KeySequenceTracker,
current_position: &mut u64,
total_count: u64,
@@ -31,23 +32,31 @@ pub async fn handle_read_only_event(
}
if config.is_enter_edit_mode_after(key.code, key.modifiers) {
let (current_input, current_pos) = if app_state.ui.show_login || app_state.ui.show_register{
let (current_input, current_pos) = if app_state.ui.show_login { // Check Login first
(
auth_state.get_current_input(),
auth_state.current_cursor_pos(),
)
} else if app_state.ui.show_register { // Then check Register
(
register_state.get_current_input(),
register_state.current_cursor_pos(),
)
} else {
(
form_state.get_current_input(),
form_state.current_cursor_pos(),
)
) // Default to Form
};
if !current_input.is_empty() && current_pos < current_input.len() {
if app_state.ui.show_login || app_state.ui.show_register{
if app_state.ui.show_login {
auth_state.set_current_cursor_pos(current_pos + 1);
*ideal_cursor_column = auth_state.current_cursor_pos();
} else {
} else if app_state.ui.show_register {
register_state.set_current_cursor_pos(current_pos + 1);
*ideal_cursor_column = register_state.current_cursor_pos();
} else { // Default to Form
form_state.set_current_cursor_pos(current_pos + 1);
*ideal_cursor_column = form_state.current_cursor_pos();
}
@@ -65,6 +74,10 @@ pub async fn handle_read_only_event(
"previous_entry",
"next_entry",
];
// Add context actions specific to register if needed, otherwise reuse login/form ones
const CONTEXT_ACTIONS_REGISTER: &[&str] = &[
// Add actions like "next_field", "prev_field" if handled differently than general read-only
];
if key.modifiers.is_empty() {
key_sequence_tracker.add_key(key.code);
@@ -81,14 +94,23 @@ pub async fn handle_read_only_event(
ideal_cursor_column,
)
.await?
} else if app_state.ui.show_login || app_state.ui.show_register && CONTEXT_ACTIONS_LOGIN.contains(&action) {
} else if app_state.ui.show_login && CONTEXT_ACTIONS_LOGIN.contains(&action) { // Handle login context actions
crate::tui::functions::login::handle_action(
action,
auth_state,
ideal_cursor_column,
)
.await?
} else if app_state.ui.show_login || app_state.ui.show_register{
} else if app_state.ui.show_register{
auth_ro::execute_action(
action,
app_state,
register_state,
ideal_cursor_column,
key_sequence_tracker,
command_message,
).await?
} else if app_state.ui.show_login {
auth_ro::execute_action(
action,
app_state,
@@ -128,14 +150,23 @@ pub async fn handle_read_only_event(
ideal_cursor_column,
)
.await?
} else if app_state.ui.show_login || app_state.ui.show_register && CONTEXT_ACTIONS_LOGIN.contains(&action) {
} else if app_state.ui.show_login && CONTEXT_ACTIONS_LOGIN.contains(&action) { // Handle login context actions
crate::tui::functions::login::handle_action(
action,
auth_state,
ideal_cursor_column,
)
.await?
} else if app_state.ui.show_login || app_state.ui.show_register {
} else if app_state.ui.show_register /* && CONTEXT_ACTIONS_REGISTER.contains(&action) */ { // Handle register general actions
auth_ro::execute_action(
action,
app_state,
register_state,
ideal_cursor_column,
key_sequence_tracker,
command_message,
).await?
} else if app_state.ui.show_login { // Handle login general actions
auth_ro::execute_action(
action,
app_state,
@@ -174,14 +205,23 @@ pub async fn handle_read_only_event(
ideal_cursor_column,
)
.await?
} else if app_state.ui.show_login || app_state.ui.show_register && CONTEXT_ACTIONS_LOGIN.contains(&action) {
} else if app_state.ui.show_login && CONTEXT_ACTIONS_LOGIN.contains(&action) { // Handle login context actions
crate::tui::functions::login::handle_action(
action,
auth_state,
ideal_cursor_column,
)
.await?
} else if app_state.ui.show_login || app_state.ui.show_register {
} else if app_state.ui.show_register /* && CONTEXT_ACTIONS_REGISTER.contains(&action) */ { // Handle register general actions
auth_ro::execute_action(
action,
app_state,
register_state,
ideal_cursor_column,
key_sequence_tracker,
command_message,
).await?
} else if app_state.ui.show_login { // Handle login general actions
auth_ro::execute_action(
action,
app_state,

View File

@@ -222,6 +222,7 @@ impl EventHandler {
config,
form_state,
auth_state,
register_state,
&mut self.key_sequence_tracker,
current_position,
total_count,

View File

@@ -243,8 +243,17 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
form_state.current_cursor_pos =
event_handler.ideal_cursor_column.min(max_cursor_pos);
}
} else if app_state.ui.show_login || app_state.ui.show_register {
// Handle cursor updates for AuthState if needed, similar to FormState
} else if app_state.ui.show_register {
if !event_handler.is_edit_mode {
let current_input = register_state.get_current_input();
let max_cursor_pos = if !current_input.is_empty() {
current_input.len() - 1
} else {
0
};
register_state.current_cursor_pos = event_handler.ideal_cursor_column.min(max_cursor_pos);
}
} else if app_state.ui.show_login {
if !event_handler.is_edit_mode {
let current_input = auth_state.get_current_input();
let max_cursor_pos = if !current_input.is_empty() {