register 2
This commit is contained in:
@@ -2,22 +2,25 @@
|
|||||||
|
|
||||||
use crate::config::binds::config::Config;
|
use crate::config::binds::config::Config;
|
||||||
use crate::services::grpc_client::GrpcClient;
|
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::functions::modes::edit::{auth_e, form_e};
|
||||||
use crate::modes::handlers::event::EventOutcome;
|
use crate::modes::handlers::event::EventOutcome;
|
||||||
|
use crate::state::state::AppState;
|
||||||
use crossterm::event::{KeyCode, KeyEvent};
|
use crossterm::event::{KeyCode, KeyEvent};
|
||||||
|
|
||||||
pub async fn handle_edit_event(
|
pub async fn handle_edit_event(
|
||||||
is_auth_context: bool,
|
|
||||||
key: KeyEvent,
|
key: KeyEvent,
|
||||||
config: &Config,
|
config: &Config,
|
||||||
form_state: &mut FormState,
|
form_state: &mut FormState,
|
||||||
auth_state: &mut AuthState,
|
auth_state: &mut AuthState,
|
||||||
|
register_state: &mut RegisterState,
|
||||||
ideal_cursor_column: &mut usize,
|
ideal_cursor_column: &mut usize,
|
||||||
command_message: &mut String,
|
command_message: &mut String,
|
||||||
current_position: &mut u64,
|
current_position: &mut u64,
|
||||||
total_count: u64,
|
total_count: u64,
|
||||||
grpc_client: &mut GrpcClient,
|
grpc_client: &mut GrpcClient,
|
||||||
|
app_state: &AppState,
|
||||||
) -> Result<String, Box<dyn std::error::Error>> {
|
) -> Result<String, Box<dyn std::error::Error>> {
|
||||||
|
|
||||||
// Global command mode check
|
// Global command mode check
|
||||||
@@ -37,7 +40,7 @@ pub async fn handle_edit_event(
|
|||||||
key.modifiers
|
key.modifiers
|
||||||
) {
|
) {
|
||||||
if matches!(action, "save" | "revert") {
|
if matches!(action, "save" | "revert") {
|
||||||
let message = if is_auth_context {
|
let message = if app_state.ui.show_login {
|
||||||
auth_e::execute_common_action(
|
auth_e::execute_common_action(
|
||||||
action,
|
action,
|
||||||
auth_state, // Concrete AuthState
|
auth_state, // Concrete AuthState
|
||||||
@@ -45,6 +48,14 @@ pub async fn handle_edit_event(
|
|||||||
current_position,
|
current_position,
|
||||||
total_count
|
total_count
|
||||||
).await
|
).await
|
||||||
|
} else if app_state.ui.show_register {
|
||||||
|
auth_e::execute_common_action(
|
||||||
|
action,
|
||||||
|
register_state,
|
||||||
|
grpc_client,
|
||||||
|
current_position,
|
||||||
|
total_count
|
||||||
|
).await
|
||||||
} else {
|
} else {
|
||||||
form_e::execute_common_action(
|
form_e::execute_common_action(
|
||||||
action,
|
action,
|
||||||
@@ -68,11 +79,21 @@ pub async fn handle_edit_event(
|
|||||||
|
|
||||||
// Edit-specific actions
|
// Edit-specific actions
|
||||||
if let Some(action) = config.get_edit_action_for_key(key.code, key.modifiers) {
|
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(
|
auth_e::execute_edit_action(
|
||||||
action,
|
action,
|
||||||
key,
|
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,
|
ideal_cursor_column,
|
||||||
grpc_client,
|
grpc_client,
|
||||||
current_position,
|
current_position,
|
||||||
@@ -82,7 +103,7 @@ pub async fn handle_edit_event(
|
|||||||
form_e::execute_edit_action(
|
form_e::execute_edit_action(
|
||||||
action,
|
action,
|
||||||
key,
|
key,
|
||||||
form_state, // Full access to FormState fields
|
form_state,
|
||||||
ideal_cursor_column,
|
ideal_cursor_column,
|
||||||
grpc_client,
|
grpc_client,
|
||||||
current_position,
|
current_position,
|
||||||
@@ -93,7 +114,7 @@ pub async fn handle_edit_event(
|
|||||||
|
|
||||||
// Character insertion
|
// Character insertion
|
||||||
if let KeyCode::Char(_) = key.code {
|
if let KeyCode::Char(_) = key.code {
|
||||||
return if is_auth_context {
|
return if app_state.ui.show_login {
|
||||||
auth_e::execute_edit_action(
|
auth_e::execute_edit_action(
|
||||||
"insert_char",
|
"insert_char",
|
||||||
key,
|
key,
|
||||||
@@ -103,6 +124,16 @@ pub async fn handle_edit_event(
|
|||||||
current_position,
|
current_position,
|
||||||
total_count
|
total_count
|
||||||
).await
|
).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 {
|
} else {
|
||||||
form_e::execute_edit_action(
|
form_e::execute_edit_action(
|
||||||
"insert_char",
|
"insert_char",
|
||||||
|
|||||||
@@ -290,16 +290,17 @@ impl EventHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let message = edit::handle_edit_event(
|
let message = edit::handle_edit_event(
|
||||||
app_state.ui.show_login,
|
|
||||||
key,
|
key,
|
||||||
config,
|
config,
|
||||||
form_state,
|
form_state,
|
||||||
auth_state,
|
auth_state,
|
||||||
|
register_state,
|
||||||
&mut self.ideal_cursor_column,
|
&mut self.ideal_cursor_column,
|
||||||
&mut self.command_message,
|
&mut self.command_message,
|
||||||
current_position,
|
current_position,
|
||||||
total_count,
|
total_count,
|
||||||
grpc_client,
|
grpc_client,
|
||||||
|
app_state,
|
||||||
).await?;
|
).await?;
|
||||||
|
|
||||||
self.key_sequence_tracker.reset();
|
self.key_sequence_tracker.reset();
|
||||||
|
|||||||
@@ -14,12 +14,14 @@ use ratatui::layout::{Constraint, Direction, Layout};
|
|||||||
use ratatui::Frame;
|
use ratatui::Frame;
|
||||||
use crate::state::pages::form::FormState;
|
use crate::state::pages::form::FormState;
|
||||||
use crate::state::pages::auth::AuthState;
|
use crate::state::pages::auth::AuthState;
|
||||||
|
use crate::state::pages::auth::RegisterState;
|
||||||
use crate::state::state::AppState;
|
use crate::state::state::AppState;
|
||||||
|
|
||||||
pub fn render_ui(
|
pub fn render_ui(
|
||||||
f: &mut Frame,
|
f: &mut Frame,
|
||||||
form_state: &mut FormState,
|
form_state: &mut FormState,
|
||||||
auth_state: &mut AuthState,
|
auth_state: &mut AuthState,
|
||||||
|
register_state: &RegisterState,
|
||||||
theme: &Theme,
|
theme: &Theme,
|
||||||
is_edit_mode: bool,
|
is_edit_mode: bool,
|
||||||
total_count: u64,
|
total_count: u64,
|
||||||
@@ -43,8 +45,16 @@ pub fn render_ui(
|
|||||||
|
|
||||||
let main_content_area = root[0];
|
let main_content_area = root[0];
|
||||||
if app_state.ui.show_intro {
|
if app_state.ui.show_intro {
|
||||||
// Use app_state's intro_state directly
|
|
||||||
app_state.ui.intro_state.render(f, main_content_area, theme);
|
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 {
|
}else if app_state.ui.show_login {
|
||||||
render_login(
|
render_login(
|
||||||
f,
|
f,
|
||||||
|
|||||||
@@ -52,9 +52,10 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
render_ui(
|
render_ui(
|
||||||
f,
|
f,
|
||||||
&mut form_state,
|
&mut form_state,
|
||||||
&mut auth_state, // Pass the single AuthState instance
|
&mut auth_state,
|
||||||
|
®ister_state,
|
||||||
&theme,
|
&theme,
|
||||||
is_edit_mode, // Use determined edit mode
|
is_edit_mode,
|
||||||
app_state.total_count,
|
app_state.total_count,
|
||||||
app_state.current_position,
|
app_state.current_position,
|
||||||
&app_state.current_dir,
|
&app_state.current_dir,
|
||||||
|
|||||||
Reference in New Issue
Block a user