register 2
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -290,16 +290,17 @@ impl EventHandler {
|
||||
}
|
||||
|
||||
let message = edit::handle_edit_event(
|
||||
app_state.ui.show_login,
|
||||
key,
|
||||
config,
|
||||
form_state,
|
||||
auth_state,
|
||||
register_state,
|
||||
&mut self.ideal_cursor_column,
|
||||
&mut self.command_message,
|
||||
current_position,
|
||||
total_count,
|
||||
grpc_client,
|
||||
app_state,
|
||||
).await?;
|
||||
|
||||
self.key_sequence_tracker.reset();
|
||||
|
||||
@@ -14,12 +14,14 @@ use ratatui::layout::{Constraint, Direction, Layout};
|
||||
use ratatui::Frame;
|
||||
use crate::state::pages::form::FormState;
|
||||
use crate::state::pages::auth::AuthState;
|
||||
use crate::state::pages::auth::RegisterState;
|
||||
use crate::state::state::AppState;
|
||||
|
||||
pub fn render_ui(
|
||||
f: &mut Frame,
|
||||
form_state: &mut FormState,
|
||||
auth_state: &mut AuthState,
|
||||
register_state: &RegisterState,
|
||||
theme: &Theme,
|
||||
is_edit_mode: bool,
|
||||
total_count: u64,
|
||||
@@ -43,8 +45,16 @@ pub fn render_ui(
|
||||
|
||||
let main_content_area = root[0];
|
||||
if app_state.ui.show_intro {
|
||||
// Use app_state's intro_state directly
|
||||
app_state.ui.intro_state.render(f, main_content_area, theme);
|
||||
} else if app_state.ui.show_register {
|
||||
render_register(
|
||||
f,
|
||||
main_content_area,
|
||||
theme,
|
||||
register_state,
|
||||
app_state,
|
||||
register_state.current_field < 4
|
||||
);
|
||||
}else if app_state.ui.show_login {
|
||||
render_login(
|
||||
f,
|
||||
|
||||
@@ -52,9 +52,10 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
|
||||
render_ui(
|
||||
f,
|
||||
&mut form_state,
|
||||
&mut auth_state, // Pass the single AuthState instance
|
||||
&mut auth_state,
|
||||
®ister_state,
|
||||
&theme,
|
||||
is_edit_mode, // Use determined edit mode
|
||||
is_edit_mode,
|
||||
app_state.total_count,
|
||||
app_state.current_position,
|
||||
&app_state.current_dir,
|
||||
|
||||
Reference in New Issue
Block a user