we successfully compiled and wen from auth state to login state and auth state
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
config::colors::themes::Theme,
|
config::colors::themes::Theme,
|
||||||
state::pages::auth::AuthState,
|
state::pages::auth::LoginState,
|
||||||
components::common::dialog,
|
components::common::dialog,
|
||||||
state::state::AppState,
|
state::state::AppState,
|
||||||
};
|
};
|
||||||
@@ -17,7 +17,7 @@ pub fn render_login(
|
|||||||
f: &mut Frame,
|
f: &mut Frame,
|
||||||
area: Rect,
|
area: Rect,
|
||||||
theme: &Theme,
|
theme: &Theme,
|
||||||
state: &AuthState,
|
login_state: &LoginState,
|
||||||
app_state: &AppState,
|
app_state: &AppState,
|
||||||
is_edit_mode: bool,
|
is_edit_mode: bool,
|
||||||
) {
|
) {
|
||||||
@@ -50,16 +50,16 @@ pub fn render_login(
|
|||||||
crate::components::handlers::canvas::render_canvas(
|
crate::components::handlers::canvas::render_canvas(
|
||||||
f,
|
f,
|
||||||
chunks[0],
|
chunks[0],
|
||||||
state,
|
login_state,
|
||||||
&["Username/Email", "Password"],
|
&["Username/Email", "Password"],
|
||||||
&state.current_field,
|
&login_state.current_field,
|
||||||
&[&state.username, &state.password],
|
&[&login_state.username, &login_state.password],
|
||||||
theme,
|
theme,
|
||||||
is_edit_mode,
|
is_edit_mode,
|
||||||
);
|
);
|
||||||
|
|
||||||
// --- ERROR MESSAGE ---
|
// --- ERROR MESSAGE ---
|
||||||
if let Some(err) = &state.error_message {
|
if let Some(err) = &login_state.error_message {
|
||||||
f.render_widget(
|
f.render_widget(
|
||||||
Paragraph::new(err.as_str())
|
Paragraph::new(err.as_str())
|
||||||
.style(Style::default().fg(Color::Red))
|
.style(Style::default().fg(Color::Red))
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// src/modes/canvas/common_mode.rs
|
// src/modes/canvas/common_mode.rs
|
||||||
|
|
||||||
use crate::tui::terminal::core::TerminalCore;
|
use crate::tui::terminal::core::TerminalCore;
|
||||||
use crate::state::pages::{form::FormState, auth::AuthState, auth::RegisterState};
|
use crate::state::pages::{form::FormState, auth::LoginState, auth::RegisterState, auth::AuthState};
|
||||||
use crate::state::state::AppState;
|
use crate::state::state::AppState;
|
||||||
use crate::services::grpc_client::GrpcClient;
|
use crate::services::grpc_client::GrpcClient;
|
||||||
use crate::services::auth::AuthClient;
|
use crate::services::auth::AuthClient;
|
||||||
@@ -17,6 +17,7 @@ pub async fn handle_core_action(
|
|||||||
action: &str,
|
action: &str,
|
||||||
form_state: &mut FormState,
|
form_state: &mut FormState,
|
||||||
auth_state: &mut AuthState,
|
auth_state: &mut AuthState,
|
||||||
|
login_state: &mut LoginState,
|
||||||
register_state: &mut RegisterState,
|
register_state: &mut RegisterState,
|
||||||
grpc_client: &mut GrpcClient,
|
grpc_client: &mut GrpcClient,
|
||||||
auth_client: &mut AuthClient,
|
auth_client: &mut AuthClient,
|
||||||
@@ -28,7 +29,7 @@ pub async fn handle_core_action(
|
|||||||
match action {
|
match action {
|
||||||
"save" => {
|
"save" => {
|
||||||
if app_state.ui.show_login {
|
if app_state.ui.show_login {
|
||||||
let message = login_save(auth_state, auth_client, app_state).await?;
|
let message = login_save(auth_state, login_state, auth_client, app_state).await?;
|
||||||
Ok(EventOutcome::Ok(message))
|
Ok(EventOutcome::Ok(message))
|
||||||
} else if app_state.ui.show_register {
|
} else if app_state.ui.show_register {
|
||||||
let message = register_save(register_state, auth_client, app_state).await?;
|
let message = register_save(register_state, auth_client, app_state).await?;
|
||||||
@@ -54,7 +55,7 @@ pub async fn handle_core_action(
|
|||||||
},
|
},
|
||||||
"save_and_quit" => {
|
"save_and_quit" => {
|
||||||
let message = if app_state.ui.show_login {
|
let message = if app_state.ui.show_login {
|
||||||
login_save(auth_state, auth_client, app_state).await?
|
login_save(auth_state, login_state, auth_client, app_state).await?
|
||||||
} else if app_state.ui.show_register {
|
} else if app_state.ui.show_register {
|
||||||
register_save(register_state, auth_client, app_state).await?
|
register_save(register_state, auth_client, app_state).await?
|
||||||
} else {
|
} else {
|
||||||
@@ -75,7 +76,7 @@ pub async fn handle_core_action(
|
|||||||
},
|
},
|
||||||
"revert" => {
|
"revert" => {
|
||||||
if app_state.ui.show_login {
|
if app_state.ui.show_login {
|
||||||
let message = login_revert(auth_state, app_state).await;
|
let message = login_revert(login_state, app_state).await;
|
||||||
Ok(EventOutcome::Ok(message))
|
Ok(EventOutcome::Ok(message))
|
||||||
} else if app_state.ui.show_register {
|
} else if app_state.ui.show_register {
|
||||||
let message = register_revert(register_state, app_state).await;
|
let message = register_revert(register_state, app_state).await;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
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, RegisterState}};
|
use crate::state::pages::{auth::{LoginState, RegisterState}};
|
||||||
use crate::state::canvas_state::CanvasState;
|
use crate::state::canvas_state::CanvasState;
|
||||||
use crate::state::pages::form::FormState;
|
use crate::state::pages::form::FormState;
|
||||||
use crate::functions::modes::edit::{auth_e, form_e};
|
use crate::functions::modes::edit::{auth_e, form_e};
|
||||||
@@ -14,7 +14,7 @@ pub async fn handle_edit_event(
|
|||||||
key: KeyEvent,
|
key: KeyEvent,
|
||||||
config: &Config,
|
config: &Config,
|
||||||
form_state: &mut FormState,
|
form_state: &mut FormState,
|
||||||
auth_state: &mut AuthState,
|
login_state: &mut LoginState,
|
||||||
register_state: &mut RegisterState,
|
register_state: &mut RegisterState,
|
||||||
ideal_cursor_column: &mut usize,
|
ideal_cursor_column: &mut usize,
|
||||||
command_message: &mut String,
|
command_message: &mut String,
|
||||||
@@ -44,7 +44,7 @@ pub async fn handle_edit_event(
|
|||||||
let message = if app_state.ui.show_login {
|
let message = if app_state.ui.show_login {
|
||||||
auth_e::execute_common_action(
|
auth_e::execute_common_action(
|
||||||
action,
|
action,
|
||||||
auth_state, // Concrete AuthState
|
login_state,
|
||||||
grpc_client,
|
grpc_client,
|
||||||
current_position,
|
current_position,
|
||||||
total_count
|
total_count
|
||||||
@@ -99,7 +99,7 @@ pub async fn handle_edit_event(
|
|||||||
auth_e::execute_edit_action(
|
auth_e::execute_edit_action(
|
||||||
action,
|
action,
|
||||||
key,
|
key,
|
||||||
auth_state,
|
login_state,
|
||||||
ideal_cursor_column,
|
ideal_cursor_column,
|
||||||
grpc_client,
|
grpc_client,
|
||||||
current_position,
|
current_position,
|
||||||
@@ -143,7 +143,7 @@ pub async fn handle_edit_event(
|
|||||||
auth_e::execute_edit_action(
|
auth_e::execute_edit_action(
|
||||||
"insert_char",
|
"insert_char",
|
||||||
key,
|
key,
|
||||||
auth_state,
|
login_state,
|
||||||
ideal_cursor_column,
|
ideal_cursor_column,
|
||||||
grpc_client,
|
grpc_client,
|
||||||
current_position,
|
current_position,
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ use crate::config::binds::key_sequences::KeySequenceTracker;
|
|||||||
use crate::services::grpc_client::GrpcClient;
|
use crate::services::grpc_client::GrpcClient;
|
||||||
use crate::state::{canvas_state::CanvasState, pages::auth::RegisterState};
|
use crate::state::{canvas_state::CanvasState, pages::auth::RegisterState};
|
||||||
use crate::state::pages::auth::AuthState;
|
use crate::state::pages::auth::AuthState;
|
||||||
|
use crate::state::pages::auth::LoginState;
|
||||||
use crate::state::pages::form::FormState;
|
use crate::state::pages::form::FormState;
|
||||||
use crate::state::state::AppState;
|
use crate::state::state::AppState;
|
||||||
use crate::functions::modes::read_only::{auth_ro, form_ro};
|
use crate::functions::modes::read_only::{auth_ro, form_ro};
|
||||||
@@ -15,7 +16,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,
|
login_state: &mut LoginState,
|
||||||
register_state: &mut RegisterState,
|
register_state: &mut RegisterState,
|
||||||
key_sequence_tracker: &mut KeySequenceTracker,
|
key_sequence_tracker: &mut KeySequenceTracker,
|
||||||
current_position: &mut u64,
|
current_position: &mut u64,
|
||||||
@@ -34,8 +35,8 @@ pub async fn handle_read_only_event(
|
|||||||
if config.is_enter_edit_mode_after(key.code, key.modifiers) {
|
if config.is_enter_edit_mode_after(key.code, key.modifiers) {
|
||||||
let (current_input, current_pos) = if app_state.ui.show_login { // Check Login first
|
let (current_input, current_pos) = if app_state.ui.show_login { // Check Login first
|
||||||
(
|
(
|
||||||
auth_state.get_current_input(),
|
login_state.get_current_input(),
|
||||||
auth_state.current_cursor_pos(),
|
login_state.current_cursor_pos(),
|
||||||
)
|
)
|
||||||
} else if app_state.ui.show_register { // Then check Register
|
} else if app_state.ui.show_register { // Then check Register
|
||||||
(
|
(
|
||||||
@@ -51,8 +52,8 @@ pub async fn handle_read_only_event(
|
|||||||
|
|
||||||
if !current_input.is_empty() && current_pos < current_input.len() {
|
if !current_input.is_empty() && current_pos < current_input.len() {
|
||||||
if app_state.ui.show_login {
|
if app_state.ui.show_login {
|
||||||
auth_state.set_current_cursor_pos(current_pos + 1);
|
login_state.set_current_cursor_pos(current_pos + 1);
|
||||||
*ideal_cursor_column = auth_state.current_cursor_pos();
|
*ideal_cursor_column = login_state.current_cursor_pos();
|
||||||
} else if app_state.ui.show_register {
|
} else if app_state.ui.show_register {
|
||||||
register_state.set_current_cursor_pos(current_pos + 1);
|
register_state.set_current_cursor_pos(current_pos + 1);
|
||||||
*ideal_cursor_column = register_state.current_cursor_pos();
|
*ideal_cursor_column = register_state.current_cursor_pos();
|
||||||
@@ -95,12 +96,7 @@ pub async fn handle_read_only_event(
|
|||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
} else if app_state.ui.show_login && CONTEXT_ACTIONS_LOGIN.contains(&action) { // Handle login context actions
|
} else if app_state.ui.show_login && CONTEXT_ACTIONS_LOGIN.contains(&action) { // Handle login context actions
|
||||||
crate::tui::functions::login::handle_action(
|
crate::tui::functions::login::handle_action(action).await?
|
||||||
action,
|
|
||||||
auth_state,
|
|
||||||
ideal_cursor_column,
|
|
||||||
)
|
|
||||||
.await?
|
|
||||||
} else if app_state.ui.show_register{
|
} else if app_state.ui.show_register{
|
||||||
auth_ro::execute_action(
|
auth_ro::execute_action(
|
||||||
action,
|
action,
|
||||||
@@ -114,7 +110,7 @@ pub async fn handle_read_only_event(
|
|||||||
auth_ro::execute_action(
|
auth_ro::execute_action(
|
||||||
action,
|
action,
|
||||||
app_state,
|
app_state,
|
||||||
auth_state,
|
login_state,
|
||||||
ideal_cursor_column,
|
ideal_cursor_column,
|
||||||
key_sequence_tracker,
|
key_sequence_tracker,
|
||||||
command_message,
|
command_message,
|
||||||
@@ -151,12 +147,7 @@ pub async fn handle_read_only_event(
|
|||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
} else if app_state.ui.show_login && CONTEXT_ACTIONS_LOGIN.contains(&action) { // Handle login context actions
|
} else if app_state.ui.show_login && CONTEXT_ACTIONS_LOGIN.contains(&action) { // Handle login context actions
|
||||||
crate::tui::functions::login::handle_action(
|
crate::tui::functions::login::handle_action(action).await?
|
||||||
action,
|
|
||||||
auth_state,
|
|
||||||
ideal_cursor_column,
|
|
||||||
)
|
|
||||||
.await?
|
|
||||||
} else if app_state.ui.show_register /* && CONTEXT_ACTIONS_REGISTER.contains(&action) */ { // Handle register general actions
|
} else if app_state.ui.show_register /* && CONTEXT_ACTIONS_REGISTER.contains(&action) */ { // Handle register general actions
|
||||||
auth_ro::execute_action(
|
auth_ro::execute_action(
|
||||||
action,
|
action,
|
||||||
@@ -170,7 +161,7 @@ pub async fn handle_read_only_event(
|
|||||||
auth_ro::execute_action(
|
auth_ro::execute_action(
|
||||||
action,
|
action,
|
||||||
app_state,
|
app_state,
|
||||||
auth_state,
|
login_state,
|
||||||
ideal_cursor_column,
|
ideal_cursor_column,
|
||||||
key_sequence_tracker,
|
key_sequence_tracker,
|
||||||
command_message,
|
command_message,
|
||||||
@@ -206,12 +197,7 @@ pub async fn handle_read_only_event(
|
|||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
} else if app_state.ui.show_login && CONTEXT_ACTIONS_LOGIN.contains(&action) { // Handle login context actions
|
} else if app_state.ui.show_login && CONTEXT_ACTIONS_LOGIN.contains(&action) { // Handle login context actions
|
||||||
crate::tui::functions::login::handle_action(
|
crate::tui::functions::login::handle_action(action).await?
|
||||||
action,
|
|
||||||
auth_state,
|
|
||||||
ideal_cursor_column,
|
|
||||||
)
|
|
||||||
.await?
|
|
||||||
} else if app_state.ui.show_register /* && CONTEXT_ACTIONS_REGISTER.contains(&action) */ { // Handle register general actions
|
} else if app_state.ui.show_register /* && CONTEXT_ACTIONS_REGISTER.contains(&action) */ { // Handle register general actions
|
||||||
auth_ro::execute_action(
|
auth_ro::execute_action(
|
||||||
action,
|
action,
|
||||||
@@ -225,7 +211,7 @@ pub async fn handle_read_only_event(
|
|||||||
auth_ro::execute_action(
|
auth_ro::execute_action(
|
||||||
action,
|
action,
|
||||||
app_state,
|
app_state,
|
||||||
auth_state,
|
login_state,
|
||||||
ideal_cursor_column,
|
ideal_cursor_column,
|
||||||
key_sequence_tracker,
|
key_sequence_tracker,
|
||||||
command_message,
|
command_message,
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use crossterm::event::{KeyEvent, KeyCode, KeyModifiers};
|
|||||||
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::form::FormState;
|
use crate::state::pages::form::FormState;
|
||||||
use crate::state::{state::AppState, pages::auth::AuthState};
|
use crate::state::{state::AppState, pages::auth::LoginState, pages::auth::RegisterState};
|
||||||
use crate::modes::common::commands::CommandHandler;
|
use crate::modes::common::commands::CommandHandler;
|
||||||
use crate::tui::terminal::core::TerminalCore;
|
use crate::tui::terminal::core::TerminalCore;
|
||||||
use crate::tui::functions::common::form::{save, revert};
|
use crate::tui::functions::common::form::{save, revert};
|
||||||
@@ -16,7 +16,8 @@ pub async fn handle_command_event(
|
|||||||
key: KeyEvent,
|
key: KeyEvent,
|
||||||
config: &Config,
|
config: &Config,
|
||||||
app_state: &AppState,
|
app_state: &AppState,
|
||||||
auth_state: &AuthState,
|
login_state: &LoginState,
|
||||||
|
register_state: &RegisterState,
|
||||||
form_state: &mut FormState,
|
form_state: &mut FormState,
|
||||||
command_input: &mut String,
|
command_input: &mut String,
|
||||||
command_message: &mut String,
|
command_message: &mut String,
|
||||||
@@ -39,7 +40,8 @@ pub async fn handle_command_event(
|
|||||||
config,
|
config,
|
||||||
form_state,
|
form_state,
|
||||||
app_state,
|
app_state,
|
||||||
auth_state,
|
login_state,
|
||||||
|
register_state,
|
||||||
command_input,
|
command_input,
|
||||||
command_message,
|
command_message,
|
||||||
grpc_client,
|
grpc_client,
|
||||||
@@ -73,7 +75,8 @@ async fn process_command(
|
|||||||
config: &Config,
|
config: &Config,
|
||||||
form_state: &mut FormState,
|
form_state: &mut FormState,
|
||||||
app_state: &AppState,
|
app_state: &AppState,
|
||||||
auth_state: &AuthState,
|
login_state: &LoginState,
|
||||||
|
register_state: &RegisterState,
|
||||||
command_input: &mut String,
|
command_input: &mut String,
|
||||||
command_message: &mut String,
|
command_message: &mut String,
|
||||||
grpc_client: &mut GrpcClient,
|
grpc_client: &mut GrpcClient,
|
||||||
@@ -101,7 +104,8 @@ async fn process_command(
|
|||||||
terminal,
|
terminal,
|
||||||
app_state,
|
app_state,
|
||||||
form_state,
|
form_state,
|
||||||
auth_state,
|
login_state,
|
||||||
|
register_state,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
command_input.clear();
|
command_input.clear();
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
// src/modes/common/commands.rs
|
// src/modes/common/commands.rs
|
||||||
use crate::tui::terminal::core::TerminalCore;
|
use crate::tui::terminal::core::TerminalCore;
|
||||||
use crate::state::state::AppState;
|
use crate::state::state::AppState;
|
||||||
use crate::state::pages::{form::FormState, auth::AuthState};
|
use crate::state::pages::{form::FormState, auth::LoginState, auth::RegisterState};
|
||||||
use crate::state::canvas_state::CanvasState;
|
use crate::state::canvas_state::CanvasState;
|
||||||
|
|
||||||
pub struct CommandHandler;
|
pub struct CommandHandler;
|
||||||
@@ -17,10 +17,11 @@ impl CommandHandler {
|
|||||||
terminal: &mut TerminalCore,
|
terminal: &mut TerminalCore,
|
||||||
app_state: &AppState,
|
app_state: &AppState,
|
||||||
form_state: &FormState,
|
form_state: &FormState,
|
||||||
auth_state: &AuthState,
|
login_state: &LoginState,
|
||||||
|
register_state: &RegisterState,
|
||||||
) -> Result<(bool, String), Box<dyn std::error::Error>> {
|
) -> Result<(bool, String), Box<dyn std::error::Error>> {
|
||||||
match action {
|
match action {
|
||||||
"quit" => self.handle_quit(terminal, app_state, form_state, auth_state).await,
|
"quit" => self.handle_quit(terminal, app_state, form_state, login_state, register_state).await,
|
||||||
"force_quit" => self.handle_force_quit(terminal).await,
|
"force_quit" => self.handle_force_quit(terminal).await,
|
||||||
"save_and_quit" => self.handle_save_quit(terminal).await,
|
"save_and_quit" => self.handle_save_quit(terminal).await,
|
||||||
_ => Ok((false, format!("Unknown command: {}", action))),
|
_ => Ok((false, format!("Unknown command: {}", action))),
|
||||||
@@ -32,11 +33,14 @@ impl CommandHandler {
|
|||||||
terminal: &mut TerminalCore,
|
terminal: &mut TerminalCore,
|
||||||
app_state: &AppState,
|
app_state: &AppState,
|
||||||
form_state: &FormState,
|
form_state: &FormState,
|
||||||
auth_state: &AuthState,
|
login_state: &LoginState,
|
||||||
|
register_state: &RegisterState,
|
||||||
) -> Result<(bool, String), Box<dyn std::error::Error>> {
|
) -> Result<(bool, String), Box<dyn std::error::Error>> {
|
||||||
// Use actual unsaved changes state instead of is_saved flag
|
// Use actual unsaved changes state instead of is_saved flag
|
||||||
let has_unsaved = if app_state.ui.show_login {
|
let has_unsaved = if app_state.ui.show_login {
|
||||||
auth_state.has_unsaved_changes()
|
login_state.has_unsaved_changes()
|
||||||
|
} else if app_state.ui.show_register {
|
||||||
|
register_state.has_unsaved_changes()
|
||||||
} else {
|
} else {
|
||||||
form_state.has_unsaved_changes
|
form_state.has_unsaved_changes
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ use crate::config::binds::config::Config;
|
|||||||
use crate::ui::handlers::context::DialogPurpose;
|
use crate::ui::handlers::context::DialogPurpose;
|
||||||
use crate::state::state::AppState;
|
use crate::state::state::AppState;
|
||||||
use crate::state::pages::auth::AuthState;
|
use crate::state::pages::auth::AuthState;
|
||||||
|
use crate::state::pages::auth::LoginState;
|
||||||
use crate::state::pages::auth::RegisterState;
|
use crate::state::pages::auth::RegisterState;
|
||||||
use crate::services::auth::AuthClient;
|
use crate::services::auth::AuthClient;
|
||||||
use crate::modes::handlers::event::EventOutcome;
|
use crate::modes::handlers::event::EventOutcome;
|
||||||
@@ -18,8 +19,8 @@ pub async fn handle_dialog_event(
|
|||||||
config: &Config,
|
config: &Config,
|
||||||
app_state: &mut AppState,
|
app_state: &mut AppState,
|
||||||
auth_state: &mut AuthState,
|
auth_state: &mut AuthState,
|
||||||
|
login_state: &mut LoginState,
|
||||||
register_state: &mut RegisterState,
|
register_state: &mut RegisterState,
|
||||||
auth_client: &mut AuthClient,
|
|
||||||
) -> Option<Result<EventOutcome, Box<dyn std::error::Error>>> {
|
) -> Option<Result<EventOutcome, Box<dyn std::error::Error>>> {
|
||||||
if let Event::Key(key) = event {
|
if let Event::Key(key) = event {
|
||||||
// Always allow Esc to dismiss
|
// Always allow Esc to dismiss
|
||||||
@@ -62,7 +63,7 @@ pub async fn handle_dialog_event(
|
|||||||
match selected_index {
|
match selected_index {
|
||||||
0 => { // "Menu" button selected
|
0 => { // "Menu" button selected
|
||||||
app_state.hide_dialog();
|
app_state.hide_dialog();
|
||||||
let message = login::back_to_main(auth_state, app_state).await;
|
let message = login::back_to_main(login_state, app_state).await;
|
||||||
return Some(Ok(EventOutcome::Ok(message)));
|
return Some(Ok(EventOutcome::Ok(message)));
|
||||||
}
|
}
|
||||||
1 => {
|
1 => {
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ use crossterm::event::KeyEvent;
|
|||||||
use crate::config::binds::config::Config;
|
use crate::config::binds::config::Config;
|
||||||
use crate::state::state::AppState;
|
use crate::state::state::AppState;
|
||||||
use crate::state::pages::form::FormState;
|
use crate::state::pages::form::FormState;
|
||||||
use crate::state::pages::auth::AuthState;
|
use crate::state::pages::auth::LoginState;
|
||||||
|
use crate::state::pages::auth::RegisterState;
|
||||||
use crate::state::canvas_state::CanvasState;
|
use crate::state::canvas_state::CanvasState;
|
||||||
use crate::ui::handlers::context::UiContext;
|
use crate::ui::handlers::context::UiContext;
|
||||||
use crate::modes::handlers::event::EventOutcome;
|
use crate::modes::handlers::event::EventOutcome;
|
||||||
@@ -14,7 +15,8 @@ pub async fn handle_navigation_event(
|
|||||||
config: &Config,
|
config: &Config,
|
||||||
form_state: &mut FormState,
|
form_state: &mut FormState,
|
||||||
app_state: &mut AppState,
|
app_state: &mut AppState,
|
||||||
auth_state: &mut AuthState,
|
login_state: &mut LoginState,
|
||||||
|
register_state: &mut RegisterState,
|
||||||
command_mode: &mut bool,
|
command_mode: &mut bool,
|
||||||
command_input: &mut String,
|
command_input: &mut String,
|
||||||
command_message: &mut String,
|
command_message: &mut String,
|
||||||
@@ -22,7 +24,7 @@ pub async fn handle_navigation_event(
|
|||||||
if let Some(action) = config.get_general_action(key.code, key.modifiers) {
|
if let Some(action) = config.get_general_action(key.code, key.modifiers) {
|
||||||
match action {
|
match action {
|
||||||
"move_up" => {
|
"move_up" => {
|
||||||
move_up(app_state, auth_state);
|
move_up(app_state, login_state, register_state);
|
||||||
return Ok(EventOutcome::Ok(String::new()));
|
return Ok(EventOutcome::Ok(String::new()));
|
||||||
}
|
}
|
||||||
"move_down" => {
|
"move_down" => {
|
||||||
@@ -78,12 +80,17 @@ pub async fn handle_navigation_event(
|
|||||||
Ok(EventOutcome::Ok(String::new()))
|
Ok(EventOutcome::Ok(String::new()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn move_up(app_state: &mut AppState, auth_state: &mut AuthState) {
|
pub fn move_up(app_state: &mut AppState, login_state: &mut LoginState, register_state: &mut RegisterState) {
|
||||||
if app_state.ui.focus_outside_canvas && app_state.ui.show_login || app_state.ui.show_register{
|
if app_state.ui.focus_outside_canvas && app_state.ui.show_login || app_state.ui.show_register{
|
||||||
if app_state.general.selected_item == 0 {
|
if app_state.general.selected_item == 0 {
|
||||||
app_state.ui.focus_outside_canvas = false;
|
app_state.ui.focus_outside_canvas = false;
|
||||||
let last_field_index = auth_state.fields().len().saturating_sub(1);
|
if app_state.ui.show_login {
|
||||||
auth_state.set_current_field(last_field_index);
|
let last_field_index = login_state.fields().len().saturating_sub(1);
|
||||||
|
login_state.set_current_field(last_field_index);
|
||||||
|
} else {
|
||||||
|
let last_field_index = register_state.fields().len().saturating_sub(1);
|
||||||
|
register_state.set_current_field(last_field_index);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
app_state.general.selected_item = app_state.general.selected_item.saturating_sub(1);
|
app_state.general.selected_item = app_state.general.selected_item.saturating_sub(1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ use crate::modes::common::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::state::pages::auth::AuthState;
|
||||||
|
use crate::state::pages::auth::LoginState;
|
||||||
use crate::state::pages::auth::RegisterState;
|
use crate::state::pages::auth::RegisterState;
|
||||||
use crate::state::canvas_state::CanvasState;
|
use crate::state::canvas_state::CanvasState;
|
||||||
use crate::ui::handlers::rat_state::UiStateHandler;
|
use crate::ui::handlers::rat_state::UiStateHandler;
|
||||||
@@ -65,6 +66,7 @@ impl EventHandler {
|
|||||||
command_handler: &mut CommandHandler,
|
command_handler: &mut CommandHandler,
|
||||||
form_state: &mut FormState,
|
form_state: &mut FormState,
|
||||||
auth_state: &mut AuthState,
|
auth_state: &mut AuthState,
|
||||||
|
login_state: &mut LoginState,
|
||||||
register_state: &mut RegisterState,
|
register_state: &mut RegisterState,
|
||||||
app_state: &mut crate::state::state::AppState,
|
app_state: &mut crate::state::state::AppState,
|
||||||
total_count: u64,
|
total_count: u64,
|
||||||
@@ -76,7 +78,7 @@ impl EventHandler {
|
|||||||
// --- DIALOG MODALITY ---
|
// --- DIALOG MODALITY ---
|
||||||
if app_state.ui.dialog.dialog_show {
|
if app_state.ui.dialog.dialog_show {
|
||||||
if let Some(dialog_result) = dialog::handle_dialog_event(
|
if let Some(dialog_result) = dialog::handle_dialog_event(
|
||||||
&event, config, app_state, auth_state, register_state, &mut self.auth_client
|
&event, config, app_state, auth_state, login_state, register_state
|
||||||
).await {
|
).await {
|
||||||
return dialog_result;
|
return dialog_result;
|
||||||
}
|
}
|
||||||
@@ -102,7 +104,8 @@ impl EventHandler {
|
|||||||
config,
|
config,
|
||||||
form_state,
|
form_state,
|
||||||
app_state,
|
app_state,
|
||||||
auth_state,
|
login_state,
|
||||||
|
register_state,
|
||||||
&mut self.command_mode,
|
&mut self.command_mode,
|
||||||
&mut self.command_input,
|
&mut self.command_input,
|
||||||
&mut self.command_message,
|
&mut self.command_message,
|
||||||
@@ -117,8 +120,8 @@ impl EventHandler {
|
|||||||
}
|
}
|
||||||
UiContext::Login => {
|
UiContext::Login => {
|
||||||
message = match index {
|
message = match index {
|
||||||
0 => login::save(auth_state, &mut self.auth_client, app_state).await?,
|
0 => login::save(auth_state, login_state, &mut self.auth_client, app_state).await?,
|
||||||
1 => login::back_to_main(auth_state, app_state).await,
|
1 => login::back_to_main(login_state, app_state).await,
|
||||||
_ => "Invalid Login Option".to_string(),
|
_ => "Invalid Login Option".to_string(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -157,20 +160,20 @@ impl EventHandler {
|
|||||||
if config.is_enter_edit_mode_after(key_code, modifiers) &&
|
if config.is_enter_edit_mode_after(key_code, modifiers) &&
|
||||||
ModeManager::can_enter_edit_mode(current_mode) {
|
ModeManager::can_enter_edit_mode(current_mode) {
|
||||||
let current_input = if app_state.ui.show_login || app_state.ui.show_register{
|
let current_input = if app_state.ui.show_login || app_state.ui.show_register{
|
||||||
auth_state.get_current_input()
|
login_state.get_current_input()
|
||||||
} else {
|
} else {
|
||||||
form_state.get_current_input()
|
form_state.get_current_input()
|
||||||
};
|
};
|
||||||
let current_cursor_pos = if app_state.ui.show_login || app_state.ui.show_register{
|
let current_cursor_pos = if app_state.ui.show_login || app_state.ui.show_register{
|
||||||
auth_state.current_cursor_pos()
|
login_state.current_cursor_pos()
|
||||||
} else {
|
} else {
|
||||||
form_state.current_cursor_pos()
|
form_state.current_cursor_pos()
|
||||||
};
|
};
|
||||||
|
|
||||||
if !current_input.is_empty() && current_cursor_pos < current_input.len() {
|
if !current_input.is_empty() && current_cursor_pos < current_input.len() {
|
||||||
if app_state.ui.show_login || app_state.ui.show_register{
|
if app_state.ui.show_login || app_state.ui.show_register{
|
||||||
auth_state.set_current_cursor_pos(current_cursor_pos + 1);
|
login_state.set_current_cursor_pos(current_cursor_pos + 1);
|
||||||
self.ideal_cursor_column = auth_state.current_cursor_pos();
|
self.ideal_cursor_column = login_state.current_cursor_pos();
|
||||||
} else {
|
} else {
|
||||||
form_state.set_current_cursor_pos(current_cursor_pos + 1);
|
form_state.set_current_cursor_pos(current_cursor_pos + 1);
|
||||||
self.ideal_cursor_column = form_state.current_cursor_pos();
|
self.ideal_cursor_column = form_state.current_cursor_pos();
|
||||||
@@ -203,6 +206,7 @@ impl EventHandler {
|
|||||||
action,
|
action,
|
||||||
form_state,
|
form_state,
|
||||||
auth_state,
|
auth_state,
|
||||||
|
login_state,
|
||||||
register_state,
|
register_state,
|
||||||
grpc_client,
|
grpc_client,
|
||||||
&mut self.auth_client,
|
&mut self.auth_client,
|
||||||
@@ -221,7 +225,7 @@ impl EventHandler {
|
|||||||
key,
|
key,
|
||||||
config,
|
config,
|
||||||
form_state,
|
form_state,
|
||||||
auth_state,
|
login_state,
|
||||||
register_state,
|
register_state,
|
||||||
&mut self.key_sequence_tracker,
|
&mut self.key_sequence_tracker,
|
||||||
current_position,
|
current_position,
|
||||||
@@ -240,7 +244,7 @@ impl EventHandler {
|
|||||||
self.edit_mode_cooldown = true;
|
self.edit_mode_cooldown = true;
|
||||||
|
|
||||||
let has_changes = if app_state.ui.show_login || app_state.ui.show_register{
|
let has_changes = if app_state.ui.show_login || app_state.ui.show_register{
|
||||||
auth_state.has_unsaved_changes()
|
login_state.has_unsaved_changes()
|
||||||
} else {
|
} else {
|
||||||
form_state.has_unsaved_changes()
|
form_state.has_unsaved_changes()
|
||||||
};
|
};
|
||||||
@@ -254,12 +258,12 @@ impl EventHandler {
|
|||||||
terminal.set_cursor_style(SetCursorStyle::SteadyBlock)?;
|
terminal.set_cursor_style(SetCursorStyle::SteadyBlock)?;
|
||||||
|
|
||||||
let current_input = if app_state.ui.show_login || app_state.ui.show_register{
|
let current_input = if app_state.ui.show_login || app_state.ui.show_register{
|
||||||
auth_state.get_current_input()
|
login_state.get_current_input()
|
||||||
} else {
|
} else {
|
||||||
form_state.get_current_input()
|
form_state.get_current_input()
|
||||||
};
|
};
|
||||||
let current_cursor_pos = if app_state.ui.show_login || app_state.ui.show_register{
|
let current_cursor_pos = if app_state.ui.show_login || app_state.ui.show_register{
|
||||||
auth_state.current_cursor_pos()
|
login_state.current_cursor_pos()
|
||||||
} else {
|
} else {
|
||||||
form_state.current_cursor_pos()
|
form_state.current_cursor_pos()
|
||||||
};
|
};
|
||||||
@@ -267,8 +271,8 @@ impl EventHandler {
|
|||||||
if !current_input.is_empty() && current_cursor_pos >= current_input.len() {
|
if !current_input.is_empty() && current_cursor_pos >= current_input.len() {
|
||||||
let new_pos = current_input.len() - 1;
|
let new_pos = current_input.len() - 1;
|
||||||
if app_state.ui.show_login || app_state.ui.show_register{
|
if app_state.ui.show_login || app_state.ui.show_register{
|
||||||
auth_state.set_current_cursor_pos(new_pos);
|
login_state.set_current_cursor_pos(new_pos);
|
||||||
self.ideal_cursor_column = auth_state.current_cursor_pos();
|
self.ideal_cursor_column = login_state.current_cursor_pos();
|
||||||
} else {
|
} else {
|
||||||
form_state.set_current_cursor_pos(new_pos);
|
form_state.set_current_cursor_pos(new_pos);
|
||||||
self.ideal_cursor_column = form_state.current_cursor_pos();
|
self.ideal_cursor_column = form_state.current_cursor_pos();
|
||||||
@@ -288,6 +292,7 @@ impl EventHandler {
|
|||||||
action,
|
action,
|
||||||
form_state,
|
form_state,
|
||||||
auth_state,
|
auth_state,
|
||||||
|
login_state,
|
||||||
register_state,
|
register_state,
|
||||||
grpc_client,
|
grpc_client,
|
||||||
&mut self.auth_client,
|
&mut self.auth_client,
|
||||||
@@ -305,7 +310,7 @@ impl EventHandler {
|
|||||||
key,
|
key,
|
||||||
config,
|
config,
|
||||||
form_state,
|
form_state,
|
||||||
auth_state,
|
login_state,
|
||||||
register_state,
|
register_state,
|
||||||
&mut self.ideal_cursor_column,
|
&mut self.ideal_cursor_column,
|
||||||
&mut self.command_message,
|
&mut self.command_message,
|
||||||
@@ -324,7 +329,8 @@ impl EventHandler {
|
|||||||
key,
|
key,
|
||||||
config,
|
config,
|
||||||
app_state,
|
app_state,
|
||||||
auth_state,
|
login_state,
|
||||||
|
register_state,
|
||||||
form_state,
|
form_state,
|
||||||
&mut self.command_input,
|
&mut self.command_input,
|
||||||
&mut self.command_message,
|
&mut self.command_message,
|
||||||
|
|||||||
@@ -23,11 +23,11 @@ pub struct AuthState {
|
|||||||
/// Represents the state of the Login form UI
|
/// Represents the state of the Login form UI
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct LoginState {
|
pub struct LoginState {
|
||||||
pub username: String, // Input field for username/email
|
pub username: String,
|
||||||
pub password: String, // Input field for password
|
pub password: String,
|
||||||
pub error_message: Option<String>, // Error message specific to login attempt
|
pub error_message: Option<String>,
|
||||||
pub current_field: usize, // 0 for username, 1 for password
|
pub current_field: usize,
|
||||||
pub current_cursor_pos: usize, // Cursor position within current field
|
pub current_cursor_pos: usize,
|
||||||
pub has_unsaved_changes: bool,
|
pub has_unsaved_changes: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use crate::services::auth::AuthClient;
|
use crate::services::auth::AuthClient;
|
||||||
use crate::state::pages::auth::AuthState;
|
use crate::state::pages::auth::AuthState;
|
||||||
|
use crate::state::pages::auth::LoginState;
|
||||||
use crate::state::state::AppState;
|
use crate::state::state::AppState;
|
||||||
use crate::state::canvas_state::CanvasState;
|
use crate::state::canvas_state::CanvasState;
|
||||||
use crate::ui::handlers::context::DialogPurpose;
|
use crate::ui::handlers::context::DialogPurpose;
|
||||||
@@ -10,14 +11,15 @@ use crate::ui::handlers::context::DialogPurpose;
|
|||||||
/// Updates AuthState and AppState on success or failure.
|
/// Updates AuthState and AppState on success or failure.
|
||||||
pub async fn save(
|
pub async fn save(
|
||||||
auth_state: &mut AuthState,
|
auth_state: &mut AuthState,
|
||||||
|
login_state: &mut LoginState,
|
||||||
auth_client: &mut AuthClient,
|
auth_client: &mut AuthClient,
|
||||||
app_state: &mut AppState,
|
app_state: &mut AppState,
|
||||||
) -> Result<String, Box<dyn std::error::Error>> {
|
) -> Result<String, Box<dyn std::error::Error>> {
|
||||||
let identifier = auth_state.username.clone();
|
let identifier = login_state.username.clone();
|
||||||
let password = auth_state.password.clone();
|
let password = login_state.password.clone();
|
||||||
|
|
||||||
// Clear previous error/dialog state before attempting
|
// Clear previous error/dialog state before attempting
|
||||||
auth_state.error_message = None;
|
login_state.error_message = None;
|
||||||
// Use the helper to ensure dialog is hidden and cleared properly
|
// Use the helper to ensure dialog is hidden and cleared properly
|
||||||
app_state.hide_dialog();
|
app_state.hide_dialog();
|
||||||
|
|
||||||
@@ -29,7 +31,7 @@ pub async fn save(
|
|||||||
auth_state.user_id = Some(response.user_id.clone());
|
auth_state.user_id = Some(response.user_id.clone());
|
||||||
auth_state.role = Some(response.role.clone());
|
auth_state.role = Some(response.role.clone());
|
||||||
auth_state.decoded_username = Some(response.username.clone());
|
auth_state.decoded_username = Some(response.username.clone());
|
||||||
auth_state.set_has_unsaved_changes(false);
|
login_state.set_has_unsaved_changes(false);
|
||||||
|
|
||||||
let success_message = format!(
|
let success_message = format!(
|
||||||
"Login Successful!\n\n\
|
"Login Successful!\n\n\
|
||||||
@@ -60,13 +62,8 @@ pub async fn save(
|
|||||||
vec!["OK".to_string()],
|
vec!["OK".to_string()],
|
||||||
DialogPurpose::LoginFailed,
|
DialogPurpose::LoginFailed,
|
||||||
);
|
);
|
||||||
// REMOVE these lines:
|
|
||||||
// app_state.ui.dialog.dialog_title = "Login Failed".to_string();
|
|
||||||
// app_state.ui.dialog.dialog_message = error_message.clone();
|
|
||||||
// app_state.ui.dialog.dialog_show = true;
|
|
||||||
// app_state.ui.dialog.dialog_button_active = true;
|
|
||||||
|
|
||||||
auth_state.set_has_unsaved_changes(true);
|
login_state.set_has_unsaved_changes(true);
|
||||||
|
|
||||||
Ok(format!("Login failed: {}", error_message))
|
Ok(format!("Login failed: {}", error_message))
|
||||||
}
|
}
|
||||||
@@ -75,27 +72,27 @@ pub async fn save(
|
|||||||
|
|
||||||
/// Reverts the login form fields to empty and returns to the previous screen (Intro).
|
/// Reverts the login form fields to empty and returns to the previous screen (Intro).
|
||||||
pub async fn revert(
|
pub async fn revert(
|
||||||
auth_state: &mut AuthState,
|
login_state: &mut LoginState,
|
||||||
app_state: &mut AppState,
|
app_state: &mut AppState,
|
||||||
) -> String {
|
) -> String {
|
||||||
// Clear the input fields
|
// Clear the input fields
|
||||||
auth_state.username.clear();
|
login_state.username.clear();
|
||||||
auth_state.password.clear();
|
login_state.password.clear();
|
||||||
auth_state.error_message = None;
|
login_state.error_message = None;
|
||||||
auth_state.set_has_unsaved_changes(false);
|
login_state.set_has_unsaved_changes(false);
|
||||||
|
|
||||||
"Login reverted".to_string()
|
"Login reverted".to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn back_to_main(
|
pub async fn back_to_main(
|
||||||
auth_state: &mut AuthState,
|
login_state: &mut LoginState,
|
||||||
app_state: &mut AppState,
|
app_state: &mut AppState,
|
||||||
) -> String {
|
) -> String {
|
||||||
// Clear the input fields
|
// Clear the input fields
|
||||||
auth_state.username.clear();
|
login_state.username.clear();
|
||||||
auth_state.password.clear();
|
login_state.password.clear();
|
||||||
auth_state.error_message = None;
|
login_state.error_message = None;
|
||||||
auth_state.set_has_unsaved_changes(false);
|
login_state.set_has_unsaved_changes(false);
|
||||||
|
|
||||||
// Ensure dialog is hidden if revert is called
|
// Ensure dialog is hidden if revert is called
|
||||||
app_state.hide_dialog(); // Uncomment if needed
|
app_state.hide_dialog(); // Uncomment if needed
|
||||||
|
|||||||
@@ -1,11 +1,6 @@
|
|||||||
// src/tui/functions/login.rs
|
// src/tui/functions/login.rs
|
||||||
use crate::state::pages::auth::AuthState;
|
|
||||||
|
|
||||||
pub async fn handle_action(
|
pub async fn handle_action(action: &str,) -> Result<String, Box<dyn std::error::Error>> {
|
||||||
action: &str,
|
|
||||||
auth_state: &mut AuthState,
|
|
||||||
ideal_cursor_column: &mut usize,
|
|
||||||
) -> Result<String, Box<dyn std::error::Error>> {
|
|
||||||
match action {
|
match action {
|
||||||
"previous_entry" => {
|
"previous_entry" => {
|
||||||
Ok("Previous entry at tui/functions/login.rs not implemented".into())
|
Ok("Previous entry at tui/functions/login.rs not implemented".into())
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ 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::LoginState;
|
||||||
use crate::state::pages::auth::RegisterState;
|
use crate::state::pages::auth::RegisterState;
|
||||||
use crate::state::state::AppState;
|
use crate::state::state::AppState;
|
||||||
|
|
||||||
@@ -21,6 +22,7 @@ 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,
|
||||||
|
login_state: &LoginState,
|
||||||
register_state: &RegisterState,
|
register_state: &RegisterState,
|
||||||
theme: &Theme,
|
theme: &Theme,
|
||||||
is_edit_mode: bool,
|
is_edit_mode: bool,
|
||||||
@@ -60,9 +62,9 @@ pub fn render_ui(
|
|||||||
f,
|
f,
|
||||||
main_content_area,
|
main_content_area,
|
||||||
theme,
|
theme,
|
||||||
auth_state,
|
login_state,
|
||||||
app_state,
|
app_state,
|
||||||
auth_state.current_field < 2
|
login_state.current_field < 2
|
||||||
);
|
);
|
||||||
} else if app_state.ui.show_admin {
|
} else if app_state.ui.show_admin {
|
||||||
// Create temporary AdminPanelState for rendering
|
// Create temporary AdminPanelState for rendering
|
||||||
|
|||||||
@@ -8,8 +8,9 @@ use crate::modes::handlers::mode_manager::{AppMode, ModeManager};
|
|||||||
use crate::services::grpc_client::GrpcClient;
|
use crate::services::grpc_client::GrpcClient;
|
||||||
use crate::services::ui_service::UiService;
|
use crate::services::ui_service::UiService;
|
||||||
use crate::state::canvas_state::CanvasState;
|
use crate::state::canvas_state::CanvasState;
|
||||||
use crate::state::pages::auth::AuthState;
|
|
||||||
use crate::state::pages::form::FormState;
|
use crate::state::pages::form::FormState;
|
||||||
|
use crate::state::pages::auth::AuthState;
|
||||||
|
use crate::state::pages::auth::LoginState;
|
||||||
use crate::state::pages::auth::RegisterState;
|
use crate::state::pages::auth::RegisterState;
|
||||||
use crate::state::state::AppState;
|
use crate::state::state::AppState;
|
||||||
// Import SaveOutcome
|
// Import SaveOutcome
|
||||||
@@ -25,6 +26,7 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
let theme = Theme::from_str(&config.colors.theme);
|
let theme = Theme::from_str(&config.colors.theme);
|
||||||
let mut auth_state = AuthState::default();
|
let mut auth_state = AuthState::default();
|
||||||
let mut register_state = RegisterState::default();
|
let mut register_state = RegisterState::default();
|
||||||
|
let mut login_state = LoginState::default();
|
||||||
|
|
||||||
// Initialize app_state first
|
// Initialize app_state first
|
||||||
let mut app_state = AppState::new()?;
|
let mut app_state = AppState::new()?;
|
||||||
@@ -55,6 +57,7 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
f,
|
f,
|
||||||
&mut form_state,
|
&mut form_state,
|
||||||
&mut auth_state,
|
&mut auth_state,
|
||||||
|
&login_state,
|
||||||
®ister_state,
|
®ister_state,
|
||||||
&theme,
|
&theme,
|
||||||
is_edit_mode,
|
is_edit_mode,
|
||||||
@@ -108,14 +111,15 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
.handle_event(
|
.handle_event(
|
||||||
event,
|
event,
|
||||||
&config,
|
&config,
|
||||||
&mut terminal, // Pass terminal mutably
|
&mut terminal,
|
||||||
&mut grpc_client,
|
&mut grpc_client,
|
||||||
&mut command_handler,
|
&mut command_handler,
|
||||||
&mut form_state,
|
&mut form_state,
|
||||||
&mut auth_state,
|
&mut auth_state,
|
||||||
|
&mut login_state,
|
||||||
&mut register_state,
|
&mut register_state,
|
||||||
&mut app_state,
|
&mut app_state,
|
||||||
total_count, // Pass the count *before* potential save
|
total_count,
|
||||||
&mut current_position,
|
&mut current_position,
|
||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
@@ -255,14 +259,13 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
}
|
}
|
||||||
} else if app_state.ui.show_login {
|
} else if app_state.ui.show_login {
|
||||||
if !event_handler.is_edit_mode {
|
if !event_handler.is_edit_mode {
|
||||||
let current_input = auth_state.get_current_input();
|
let current_input = login_state.get_current_input();
|
||||||
let max_cursor_pos = if !current_input.is_empty() {
|
let max_cursor_pos = if !current_input.is_empty() {
|
||||||
current_input.len() - 1
|
current_input.len() - 1
|
||||||
} else {
|
} else {
|
||||||
0
|
0
|
||||||
};
|
};
|
||||||
auth_state.current_cursor_pos =
|
login_state.current_cursor_pos = event_handler.ideal_cursor_column.min(max_cursor_pos);
|
||||||
event_handler.ideal_cursor_column.min(max_cursor_pos);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user