register 2

This commit is contained in:
filipriec
2025-04-10 19:27:04 +02:00
parent b51e76e366
commit 431882ece9
4 changed files with 54 additions and 11 deletions

View File

@@ -2,22 +2,25 @@
use crate::config::binds::config::Config;
use crate::services::grpc_client::GrpcClient;
use crate::state::pages::{auth::AuthState, form::FormState};
use crate::state::pages::{auth::{AuthState, RegisterState}};
use crate::state::pages::form::FormState;
use crate::functions::modes::edit::{auth_e, form_e};
use crate::modes::handlers::event::EventOutcome;
use crate::state::state::AppState;
use crossterm::event::{KeyCode, KeyEvent};
pub async fn handle_edit_event(
is_auth_context: bool,
key: KeyEvent,
config: &Config,
form_state: &mut FormState,
auth_state: &mut AuthState,
register_state: &mut RegisterState,
ideal_cursor_column: &mut usize,
command_message: &mut String,
current_position: &mut u64,
total_count: u64,
grpc_client: &mut GrpcClient,
app_state: &AppState,
) -> Result<String, Box<dyn std::error::Error>> {
// Global command mode check
@@ -37,7 +40,7 @@ pub async fn handle_edit_event(
key.modifiers
) {
if matches!(action, "save" | "revert") {
let message = if is_auth_context {
let message = if app_state.ui.show_login {
auth_e::execute_common_action(
action,
auth_state, // Concrete AuthState
@@ -45,6 +48,14 @@ pub async fn handle_edit_event(
current_position,
total_count
).await
} else if app_state.ui.show_register {
auth_e::execute_common_action(
action,
register_state,
grpc_client,
current_position,
total_count
).await
} else {
form_e::execute_common_action(
action,
@@ -68,11 +79,21 @@ pub async fn handle_edit_event(
// Edit-specific actions
if let Some(action) = config.get_edit_action_for_key(key.code, key.modifiers) {
return if is_auth_context {
return if app_state.ui.show_login {
auth_e::execute_edit_action(
action,
key,
auth_state, // Full access to AuthState fields
auth_state,
ideal_cursor_column,
grpc_client,
current_position,
total_count
).await
} else if app_state.ui.show_register {
auth_e::execute_edit_action(
action,
key,
register_state,
ideal_cursor_column,
grpc_client,
current_position,
@@ -82,7 +103,7 @@ pub async fn handle_edit_event(
form_e::execute_edit_action(
action,
key,
form_state, // Full access to FormState fields
form_state,
ideal_cursor_column,
grpc_client,
current_position,
@@ -93,7 +114,7 @@ pub async fn handle_edit_event(
// Character insertion
if let KeyCode::Char(_) = key.code {
return if is_auth_context {
return if app_state.ui.show_login {
auth_e::execute_edit_action(
"insert_char",
key,
@@ -103,6 +124,16 @@ pub async fn handle_edit_event(
current_position,
total_count
).await
} else if app_state.ui.show_register {
auth_e::execute_edit_action(
"insert_char",
key,
register_state,
ideal_cursor_column,
grpc_client,
current_position,
total_count
).await
} else {
form_e::execute_edit_action(
"insert_char",