Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2d724876eb | ||
|
|
1927d1fa4d | ||
|
|
d995fab0e4 | ||
|
|
b4135c1626 | ||
|
|
3d0a9f2082 |
@@ -2,9 +2,9 @@
|
||||
|
||||
use crate::{
|
||||
config::colors::themes::Theme,
|
||||
state::pages::auth::AuthState,
|
||||
state::pages::auth::LoginState,
|
||||
components::common::dialog,
|
||||
state::state::AppState,
|
||||
state::app::state::AppState,
|
||||
};
|
||||
use ratatui::{
|
||||
layout::{Alignment, Constraint, Direction, Layout, Rect, Margin},
|
||||
@@ -17,7 +17,7 @@ pub fn render_login(
|
||||
f: &mut Frame,
|
||||
area: Rect,
|
||||
theme: &Theme,
|
||||
state: &AuthState,
|
||||
login_state: &LoginState,
|
||||
app_state: &AppState,
|
||||
is_edit_mode: bool,
|
||||
) {
|
||||
@@ -50,16 +50,16 @@ pub fn render_login(
|
||||
crate::components::handlers::canvas::render_canvas(
|
||||
f,
|
||||
chunks[0],
|
||||
state,
|
||||
login_state,
|
||||
&["Username/Email", "Password"],
|
||||
&state.current_field,
|
||||
&[&state.username, &state.password],
|
||||
&login_state.current_field,
|
||||
&[&login_state.username, &login_state.password],
|
||||
theme,
|
||||
is_edit_mode,
|
||||
);
|
||||
|
||||
// --- ERROR MESSAGE ---
|
||||
if let Some(err) = &state.error_message {
|
||||
if let Some(err) = &login_state.error_message {
|
||||
f.render_widget(
|
||||
Paragraph::new(err.as_str())
|
||||
.style(Style::default().fg(Color::Red))
|
||||
|
||||
@@ -4,8 +4,8 @@ use crate::{
|
||||
config::colors::themes::Theme,
|
||||
state::pages::auth::RegisterState, // Use RegisterState
|
||||
components::common::{dialog, autocomplete},
|
||||
state::state::AppState,
|
||||
state::canvas_state::CanvasState,
|
||||
state::app::state::AppState,
|
||||
state::pages::canvas_state::CanvasState,
|
||||
modes::handlers::mode_manager::AppMode,
|
||||
};
|
||||
use ratatui::{
|
||||
|
||||
@@ -6,7 +6,7 @@ use ratatui::{
|
||||
Frame,
|
||||
};
|
||||
use crate::config::colors::themes::Theme;
|
||||
use crate::state::canvas_state::CanvasState;
|
||||
use crate::state::pages::canvas_state::CanvasState;
|
||||
use crate::components::handlers::canvas::render_canvas;
|
||||
|
||||
pub fn render_form(
|
||||
|
||||
@@ -8,7 +8,7 @@ use ratatui::{
|
||||
prelude::Alignment,
|
||||
};
|
||||
use crate::config::colors::themes::Theme;
|
||||
use crate::state::canvas_state::CanvasState;
|
||||
use crate::state::pages::canvas_state::CanvasState;
|
||||
use crate::components::common::autocomplete;
|
||||
use crate::components::render_autocomplete_dropdown;
|
||||
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
|
||||
pub mod read_only;
|
||||
pub mod edit;
|
||||
|
||||
pub mod navigation;
|
||||
|
||||
pub use read_only::*;
|
||||
pub use edit::*;
|
||||
pub use navigation::*;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// src/functions/modes/edit/auth_e.rs
|
||||
|
||||
use crate::services::grpc_client::GrpcClient;
|
||||
use crate::state::canvas_state::CanvasState;
|
||||
use crate::state::pages::canvas_state::CanvasState;
|
||||
use crate::state::pages::form::FormState;
|
||||
use crate::state::pages::auth::RegisterState;
|
||||
use crate::tui::functions::common::form::{revert, save};
|
||||
@@ -300,9 +300,9 @@ pub async fn execute_edit_action<S: CanvasState + Any + Send>(
|
||||
|
||||
// --- Autocomplete Actions ---
|
||||
"suggestion_down" | "suggestion_up" | "select_suggestion" | "exit_suggestion_mode" => {
|
||||
// Attempt to downcast to RegisterState
|
||||
// Attempt to downcast to RegisterState to handle suggestion logic here
|
||||
if let Some(register_state) = (state as &mut dyn Any).downcast_mut::<RegisterState>() {
|
||||
// Only handle if it's the role field (index 4) and suggestions are shown (except for hide)
|
||||
// Only handle if it's the role field (index 4)
|
||||
if register_state.current_field() == 4 {
|
||||
match action {
|
||||
"suggestion_down" if register_state.in_suggestion_mode => {
|
||||
@@ -319,34 +319,37 @@ pub async fn execute_edit_action<S: CanvasState + Any + Send>(
|
||||
}
|
||||
"select_suggestion" if register_state.in_suggestion_mode => {
|
||||
if let Some(index) = register_state.selected_suggestion_index {
|
||||
let selected_role = register_state.role_suggestions[index].clone();
|
||||
register_state.role = selected_role.clone(); // Update the role field
|
||||
register_state.in_suggestion_mode = false; // Exit suggestion mode
|
||||
register_state.show_role_suggestions = false; // Hide suggestions
|
||||
register_state.selected_suggestion_index = None; // Clear selection
|
||||
Ok(format!("Selected role: {}", selected_role)) // Return success message
|
||||
if let Some(selected_role) = register_state.role_suggestions.get(index).cloned() {
|
||||
register_state.role = selected_role.clone(); // Update the role field
|
||||
register_state.in_suggestion_mode = false; // Exit suggestion mode
|
||||
register_state.show_role_suggestions = false; // Hide suggestions
|
||||
register_state.selected_suggestion_index = None; // Clear selection
|
||||
Ok(format!("Selected role: {}", selected_role)) // Return success message
|
||||
} else {
|
||||
Ok("Selected suggestion index out of bounds.".to_string()) // Error case
|
||||
}
|
||||
} else {
|
||||
Ok("No suggestion selected".to_string())
|
||||
|
||||
}
|
||||
}
|
||||
"exit_suggestion_mode" => { // Handle Esc
|
||||
"exit_suggestion_mode" => { // Handle Esc or other conditions
|
||||
register_state.show_role_suggestions = false;
|
||||
register_state.selected_suggestion_index = None;
|
||||
register_state.in_suggestion_mode = false;
|
||||
Ok("Suggestions hidden".to_string())
|
||||
}
|
||||
"suggestion_down" | "suggestion_up" | "select_suggestion" => {
|
||||
Ok("Suggestion action ignored: Not in suggestion mode.".to_string())
|
||||
_ => {
|
||||
// Action is suggestion-related but state doesn't match (e.g., not in suggestion mode)
|
||||
Ok("Suggestion action ignored: State mismatch.".to_string())
|
||||
}
|
||||
_ => Ok("".to_string())
|
||||
}
|
||||
} else {
|
||||
Ok("".to_string())
|
||||
}
|
||||
// It's RegisterState, but not the role field
|
||||
Ok("Suggestion action ignored: Not on role field.".to_string())
|
||||
}
|
||||
} else {
|
||||
// Downcast failed - this action is only for RegisterState
|
||||
Ok(format!("Action '{}' not applicable for this form type.", action))
|
||||
Ok(format!("Action '{}' not applicable for this state type.", action))
|
||||
}
|
||||
}
|
||||
// --- End Autocomplete Actions ---
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// src/functions/modes/edit/form_e.rs
|
||||
|
||||
use crate::services::grpc_client::GrpcClient;
|
||||
use crate::state::canvas_state::CanvasState;
|
||||
use crate::state::pages::canvas_state::CanvasState;
|
||||
use crate::state::pages::form::FormState;
|
||||
use crate::tui::functions::common::form::{revert, save};
|
||||
use crate::tui::functions::common::form::SaveOutcome;
|
||||
|
||||
3
client/src/functions/modes/navigation.rs
Normal file
3
client/src/functions/modes/navigation.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
// src/functions/modes/navigation.rs
|
||||
|
||||
pub mod admin_nav;
|
||||
36
client/src/functions/modes/navigation/admin_nav.rs
Normal file
36
client/src/functions/modes/navigation/admin_nav.rs
Normal file
@@ -0,0 +1,36 @@
|
||||
// src/functions/modes/navigation/admin_nav.rs
|
||||
|
||||
use crate::state::app::state::AppState;
|
||||
use crate::state::pages::admin::AdminState;
|
||||
|
||||
/// Handles moving the selection up in the admin profile list.
|
||||
pub fn move_admin_list_up(app_state: &AppState, admin_state: &mut AdminState) {
|
||||
// Read profile count directly from app_state where the source data lives
|
||||
let profile_count = app_state.profile_tree.profiles.len();
|
||||
if profile_count == 0 {
|
||||
admin_state.list_state.select(None); // Ensure nothing selected if empty
|
||||
return;
|
||||
}
|
||||
|
||||
let current_index = admin_state.get_selected_index().unwrap_or(0);
|
||||
let new_index = if current_index == 0 {
|
||||
profile_count - 1 // Wrap to end
|
||||
} else {
|
||||
current_index.saturating_sub(1) // Move up
|
||||
};
|
||||
admin_state.list_state.select(Some(new_index));
|
||||
}
|
||||
|
||||
/// Handles moving the selection down in the admin profile list.
|
||||
pub fn move_admin_list_down(app_state: &AppState, admin_state: &mut AdminState) {
|
||||
// Read profile count directly from app_state
|
||||
let profile_count = app_state.profile_tree.profiles.len();
|
||||
if profile_count == 0 {
|
||||
admin_state.list_state.select(None); // Ensure nothing selected if empty
|
||||
return;
|
||||
}
|
||||
|
||||
let current_index = admin_state.get_selected_index().unwrap_or(0);
|
||||
let new_index = (current_index + 1) % profile_count; // Wrap around
|
||||
admin_state.list_state.select(Some(new_index));
|
||||
}
|
||||
@@ -1,8 +1,8 @@
|
||||
// src/functions/modes/read_only/auth_ro.rs
|
||||
|
||||
use crate::config::binds::key_sequences::KeySequenceTracker;
|
||||
use crate::state::canvas_state::CanvasState;
|
||||
use crate::state::state::AppState;
|
||||
use crate::state::pages::canvas_state::CanvasState;
|
||||
use crate::state::app::state::AppState;
|
||||
use std::error::Error;
|
||||
|
||||
#[derive(PartialEq)]
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// src/functions/modes/read_only/form_ro.rs
|
||||
|
||||
use crate::config::binds::key_sequences::KeySequenceTracker;
|
||||
use crate::state::canvas_state::CanvasState;
|
||||
use crate::state::pages::canvas_state::CanvasState;
|
||||
use std::error::Error;
|
||||
|
||||
#[derive(PartialEq)]
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// src/modes/canvas/common_mode.rs
|
||||
|
||||
use crate::tui::terminal::core::TerminalCore;
|
||||
use crate::state::pages::{form::FormState, auth::AuthState, auth::RegisterState};
|
||||
use crate::state::state::AppState;
|
||||
use crate::state::pages::{form::FormState, auth::LoginState, auth::RegisterState, auth::AuthState};
|
||||
use crate::state::app::state::AppState;
|
||||
use crate::services::grpc_client::GrpcClient;
|
||||
use crate::services::auth::AuthClient;
|
||||
use crate::modes::handlers::event::EventOutcome;
|
||||
@@ -17,6 +17,7 @@ pub async fn handle_core_action(
|
||||
action: &str,
|
||||
form_state: &mut FormState,
|
||||
auth_state: &mut AuthState,
|
||||
login_state: &mut LoginState,
|
||||
register_state: &mut RegisterState,
|
||||
grpc_client: &mut GrpcClient,
|
||||
auth_client: &mut AuthClient,
|
||||
@@ -28,7 +29,7 @@ pub async fn handle_core_action(
|
||||
match action {
|
||||
"save" => {
|
||||
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))
|
||||
} else if app_state.ui.show_register {
|
||||
let message = register_save(register_state, auth_client, app_state).await?;
|
||||
@@ -54,7 +55,7 @@ pub async fn handle_core_action(
|
||||
},
|
||||
"save_and_quit" => {
|
||||
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 {
|
||||
register_save(register_state, auth_client, app_state).await?
|
||||
} else {
|
||||
@@ -75,7 +76,7 @@ pub async fn handle_core_action(
|
||||
},
|
||||
"revert" => {
|
||||
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))
|
||||
} else if app_state.ui.show_register {
|
||||
let message = register_revert(register_state, app_state).await;
|
||||
|
||||
@@ -2,19 +2,19 @@
|
||||
|
||||
use crate::config::binds::config::Config;
|
||||
use crate::services::grpc_client::GrpcClient;
|
||||
use crate::state::pages::{auth::{AuthState, RegisterState}};
|
||||
use crate::state::canvas_state::CanvasState;
|
||||
use crate::state::pages::{auth::{LoginState, RegisterState}};
|
||||
use crate::state::pages::canvas_state::CanvasState;
|
||||
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 crate::state::app::state::AppState;
|
||||
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
|
||||
|
||||
pub async fn handle_edit_event(
|
||||
key: KeyEvent,
|
||||
config: &Config,
|
||||
form_state: &mut FormState,
|
||||
auth_state: &mut AuthState,
|
||||
login_state: &mut LoginState,
|
||||
register_state: &mut RegisterState,
|
||||
ideal_cursor_column: &mut usize,
|
||||
command_message: &mut String,
|
||||
@@ -44,7 +44,7 @@ pub async fn handle_edit_event(
|
||||
let message = if app_state.ui.show_login {
|
||||
auth_e::execute_common_action(
|
||||
action,
|
||||
auth_state, // Concrete AuthState
|
||||
login_state,
|
||||
grpc_client,
|
||||
current_position,
|
||||
total_count
|
||||
@@ -99,7 +99,7 @@ pub async fn handle_edit_event(
|
||||
auth_e::execute_edit_action(
|
||||
action,
|
||||
key,
|
||||
auth_state,
|
||||
login_state,
|
||||
ideal_cursor_column,
|
||||
grpc_client,
|
||||
current_position,
|
||||
@@ -143,7 +143,7 @@ pub async fn handle_edit_event(
|
||||
auth_e::execute_edit_action(
|
||||
"insert_char",
|
||||
key,
|
||||
auth_state,
|
||||
login_state,
|
||||
ideal_cursor_column,
|
||||
grpc_client,
|
||||
current_position,
|
||||
|
||||
@@ -3,10 +3,11 @@
|
||||
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, pages::auth::RegisterState};
|
||||
use crate::state::pages::{canvas_state::CanvasState, auth::RegisterState};
|
||||
use crate::state::pages::auth::AuthState;
|
||||
use crate::state::pages::auth::LoginState;
|
||||
use crate::state::pages::form::FormState;
|
||||
use crate::state::state::AppState;
|
||||
use crate::state::app::state::AppState;
|
||||
use crate::functions::modes::read_only::{auth_ro, form_ro};
|
||||
use crossterm::event::KeyEvent;
|
||||
|
||||
@@ -15,7 +16,7 @@ pub async fn handle_read_only_event(
|
||||
key: KeyEvent,
|
||||
config: &Config,
|
||||
form_state: &mut FormState,
|
||||
auth_state: &mut AuthState,
|
||||
login_state: &mut LoginState,
|
||||
register_state: &mut RegisterState,
|
||||
key_sequence_tracker: &mut KeySequenceTracker,
|
||||
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) {
|
||||
let (current_input, current_pos) = if app_state.ui.show_login { // Check Login first
|
||||
(
|
||||
auth_state.get_current_input(),
|
||||
auth_state.current_cursor_pos(),
|
||||
login_state.get_current_input(),
|
||||
login_state.current_cursor_pos(),
|
||||
)
|
||||
} 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 app_state.ui.show_login {
|
||||
auth_state.set_current_cursor_pos(current_pos + 1);
|
||||
*ideal_cursor_column = auth_state.current_cursor_pos();
|
||||
login_state.set_current_cursor_pos(current_pos + 1);
|
||||
*ideal_cursor_column = login_state.current_cursor_pos();
|
||||
} else if app_state.ui.show_register {
|
||||
register_state.set_current_cursor_pos(current_pos + 1);
|
||||
*ideal_cursor_column = register_state.current_cursor_pos();
|
||||
@@ -95,12 +96,7 @@ pub async fn handle_read_only_event(
|
||||
)
|
||||
.await?
|
||||
} 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?
|
||||
crate::tui::functions::login::handle_action(action).await?
|
||||
} else if app_state.ui.show_register{
|
||||
auth_ro::execute_action(
|
||||
action,
|
||||
@@ -114,7 +110,7 @@ pub async fn handle_read_only_event(
|
||||
auth_ro::execute_action(
|
||||
action,
|
||||
app_state,
|
||||
auth_state,
|
||||
login_state,
|
||||
ideal_cursor_column,
|
||||
key_sequence_tracker,
|
||||
command_message,
|
||||
@@ -151,12 +147,7 @@ pub async fn handle_read_only_event(
|
||||
)
|
||||
.await?
|
||||
} 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?
|
||||
crate::tui::functions::login::handle_action(action).await?
|
||||
} else if app_state.ui.show_register /* && CONTEXT_ACTIONS_REGISTER.contains(&action) */ { // Handle register general actions
|
||||
auth_ro::execute_action(
|
||||
action,
|
||||
@@ -170,7 +161,7 @@ pub async fn handle_read_only_event(
|
||||
auth_ro::execute_action(
|
||||
action,
|
||||
app_state,
|
||||
auth_state,
|
||||
login_state,
|
||||
ideal_cursor_column,
|
||||
key_sequence_tracker,
|
||||
command_message,
|
||||
@@ -206,12 +197,7 @@ pub async fn handle_read_only_event(
|
||||
)
|
||||
.await?
|
||||
} 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?
|
||||
crate::tui::functions::login::handle_action(action).await?
|
||||
} else if app_state.ui.show_register /* && CONTEXT_ACTIONS_REGISTER.contains(&action) */ { // Handle register general actions
|
||||
auth_ro::execute_action(
|
||||
action,
|
||||
@@ -225,7 +211,7 @@ pub async fn handle_read_only_event(
|
||||
auth_ro::execute_action(
|
||||
action,
|
||||
app_state,
|
||||
auth_state,
|
||||
login_state,
|
||||
ideal_cursor_column,
|
||||
key_sequence_tracker,
|
||||
command_message,
|
||||
|
||||
@@ -4,7 +4,7 @@ use crossterm::event::{KeyEvent, KeyCode, KeyModifiers};
|
||||
use crate::config::binds::config::Config;
|
||||
use crate::services::grpc_client::GrpcClient;
|
||||
use crate::state::pages::form::FormState;
|
||||
use crate::state::{state::AppState, pages::auth::AuthState};
|
||||
use crate::state::{app::state::AppState, pages::auth::LoginState, pages::auth::RegisterState};
|
||||
use crate::modes::common::commands::CommandHandler;
|
||||
use crate::tui::terminal::core::TerminalCore;
|
||||
use crate::tui::functions::common::form::{save, revert};
|
||||
@@ -16,7 +16,8 @@ pub async fn handle_command_event(
|
||||
key: KeyEvent,
|
||||
config: &Config,
|
||||
app_state: &AppState,
|
||||
auth_state: &AuthState,
|
||||
login_state: &LoginState,
|
||||
register_state: &RegisterState,
|
||||
form_state: &mut FormState,
|
||||
command_input: &mut String,
|
||||
command_message: &mut String,
|
||||
@@ -39,7 +40,8 @@ pub async fn handle_command_event(
|
||||
config,
|
||||
form_state,
|
||||
app_state,
|
||||
auth_state,
|
||||
login_state,
|
||||
register_state,
|
||||
command_input,
|
||||
command_message,
|
||||
grpc_client,
|
||||
@@ -73,7 +75,8 @@ async fn process_command(
|
||||
config: &Config,
|
||||
form_state: &mut FormState,
|
||||
app_state: &AppState,
|
||||
auth_state: &AuthState,
|
||||
login_state: &LoginState,
|
||||
register_state: &RegisterState,
|
||||
command_input: &mut String,
|
||||
command_message: &mut String,
|
||||
grpc_client: &mut GrpcClient,
|
||||
@@ -101,7 +104,8 @@ async fn process_command(
|
||||
terminal,
|
||||
app_state,
|
||||
form_state,
|
||||
auth_state,
|
||||
login_state,
|
||||
register_state,
|
||||
)
|
||||
.await?;
|
||||
command_input.clear();
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
// src/modes/common/commands.rs
|
||||
use crate::tui::terminal::core::TerminalCore;
|
||||
use crate::state::state::AppState;
|
||||
use crate::state::pages::{form::FormState, auth::AuthState};
|
||||
use crate::state::canvas_state::CanvasState;
|
||||
use crate::state::app::state::AppState;
|
||||
use crate::state::pages::{form::FormState, auth::LoginState, auth::RegisterState};
|
||||
use crate::state::pages::canvas_state::CanvasState;
|
||||
|
||||
pub struct CommandHandler;
|
||||
|
||||
@@ -17,10 +17,11 @@ impl CommandHandler {
|
||||
terminal: &mut TerminalCore,
|
||||
app_state: &AppState,
|
||||
form_state: &FormState,
|
||||
auth_state: &AuthState,
|
||||
login_state: &LoginState,
|
||||
register_state: &RegisterState,
|
||||
) -> Result<(bool, String), Box<dyn std::error::Error>> {
|
||||
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,
|
||||
"save_and_quit" => self.handle_save_quit(terminal).await,
|
||||
_ => Ok((false, format!("Unknown command: {}", action))),
|
||||
@@ -32,11 +33,14 @@ impl CommandHandler {
|
||||
terminal: &mut TerminalCore,
|
||||
app_state: &AppState,
|
||||
form_state: &FormState,
|
||||
auth_state: &AuthState,
|
||||
login_state: &LoginState,
|
||||
register_state: &RegisterState,
|
||||
) -> Result<(bool, String), Box<dyn std::error::Error>> {
|
||||
// Use actual unsaved changes state instead of is_saved flag
|
||||
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 {
|
||||
form_state.has_unsaved_changes
|
||||
};
|
||||
|
||||
@@ -3,8 +3,9 @@
|
||||
use crossterm::event::{Event, KeyCode};
|
||||
use crate::config::binds::config::Config;
|
||||
use crate::ui::handlers::context::DialogPurpose;
|
||||
use crate::state::state::AppState;
|
||||
use crate::state::app::state::AppState;
|
||||
use crate::state::pages::auth::AuthState;
|
||||
use crate::state::pages::auth::LoginState;
|
||||
use crate::state::pages::auth::RegisterState;
|
||||
use crate::services::auth::AuthClient;
|
||||
use crate::modes::handlers::event::EventOutcome;
|
||||
@@ -18,8 +19,8 @@ pub async fn handle_dialog_event(
|
||||
config: &Config,
|
||||
app_state: &mut AppState,
|
||||
auth_state: &mut AuthState,
|
||||
login_state: &mut LoginState,
|
||||
register_state: &mut RegisterState,
|
||||
auth_client: &mut AuthClient,
|
||||
) -> Option<Result<EventOutcome, Box<dyn std::error::Error>>> {
|
||||
if let Event::Key(key) = event {
|
||||
// Always allow Esc to dismiss
|
||||
@@ -62,7 +63,7 @@ pub async fn handle_dialog_event(
|
||||
match selected_index {
|
||||
0 => { // "Menu" button selected
|
||||
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)));
|
||||
}
|
||||
1 => {
|
||||
|
||||
@@ -2,19 +2,24 @@
|
||||
|
||||
use crossterm::event::KeyEvent;
|
||||
use crate::config::binds::config::Config;
|
||||
use crate::state::state::AppState;
|
||||
use crate::state::app::state::AppState;
|
||||
use crate::state::pages::form::FormState;
|
||||
use crate::state::pages::auth::AuthState;
|
||||
use crate::state::canvas_state::CanvasState;
|
||||
use crate::state::pages::auth::LoginState;
|
||||
use crate::state::pages::auth::RegisterState;
|
||||
use crate::state::pages::admin::AdminState;
|
||||
use crate::state::pages::canvas_state::CanvasState;
|
||||
use crate::ui::handlers::context::UiContext;
|
||||
use crate::modes::handlers::event::EventOutcome;
|
||||
use crate::functions::modes::navigation::admin_nav;
|
||||
|
||||
pub async fn handle_navigation_event(
|
||||
key: KeyEvent,
|
||||
config: &Config,
|
||||
form_state: &mut FormState,
|
||||
app_state: &mut AppState,
|
||||
auth_state: &mut AuthState,
|
||||
login_state: &mut LoginState,
|
||||
register_state: &mut RegisterState,
|
||||
admin_state: &mut AdminState,
|
||||
command_mode: &mut bool,
|
||||
command_input: &mut String,
|
||||
command_message: &mut String,
|
||||
@@ -22,11 +27,11 @@ pub async fn handle_navigation_event(
|
||||
if let Some(action) = config.get_general_action(key.code, key.modifiers) {
|
||||
match action {
|
||||
"move_up" => {
|
||||
move_up(app_state, auth_state);
|
||||
move_up(app_state, login_state, register_state, admin_state);
|
||||
return Ok(EventOutcome::Ok(String::new()));
|
||||
}
|
||||
"move_down" => {
|
||||
move_down(app_state);
|
||||
move_down(app_state, admin_state);
|
||||
return Ok(EventOutcome::Ok(String::new()));
|
||||
}
|
||||
"next_option" => {
|
||||
@@ -78,34 +83,28 @@ pub async fn handle_navigation_event(
|
||||
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, admin_state: &mut AdminState) {
|
||||
if app_state.ui.focus_outside_canvas && app_state.ui.show_login || app_state.ui.show_register{
|
||||
if app_state.general.selected_item == 0 {
|
||||
app_state.ui.focus_outside_canvas = false;
|
||||
let last_field_index = auth_state.fields().len().saturating_sub(1);
|
||||
auth_state.set_current_field(last_field_index);
|
||||
if app_state.ui.show_login {
|
||||
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 {
|
||||
app_state.general.selected_item = app_state.general.selected_item.saturating_sub(1);
|
||||
}
|
||||
} else if app_state.ui.show_intro {
|
||||
app_state.ui.intro_state.previous_option();
|
||||
} else if app_state.ui.show_admin {
|
||||
// Assuming profile_tree.profiles is the list we're navigating
|
||||
let profile_count = app_state.profile_tree.profiles.len();
|
||||
if profile_count == 0 {
|
||||
return;
|
||||
}
|
||||
|
||||
// Use general state for tracking selection in admin panel
|
||||
if app_state.general.selected_item == 0 {
|
||||
app_state.general.selected_item = profile_count - 1;
|
||||
} else {
|
||||
app_state.general.selected_item = app_state.general.selected_item.saturating_sub(1);
|
||||
}
|
||||
admin_nav::move_admin_list_up(app_state, admin_state);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn move_down(app_state: &mut AppState) {
|
||||
pub fn move_down(app_state: &mut AppState, admin_state: &mut AdminState) {
|
||||
if app_state.ui.focus_outside_canvas && app_state.ui.show_login || app_state.ui.show_register {
|
||||
let num_general_elements = 2;
|
||||
if app_state.general.selected_item < num_general_elements - 1 {
|
||||
@@ -120,7 +119,7 @@ pub fn move_down(app_state: &mut AppState) {
|
||||
return;
|
||||
}
|
||||
|
||||
app_state.general.selected_item = (app_state.general.selected_item + 1) % profile_count;
|
||||
admin_nav::move_admin_list_down(app_state, admin_state);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,11 @@ use crate::modes::common::commands::CommandHandler;
|
||||
use crate::config::binds::config::Config;
|
||||
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::pages::admin::AdminState;
|
||||
use crate::state::app::state::AppState;
|
||||
use crate::state::pages::canvas_state::CanvasState;
|
||||
use crate::ui::handlers::rat_state::UiStateHandler;
|
||||
use crate::ui::handlers::context::UiContext;
|
||||
use crate::tui::functions::{intro, admin};
|
||||
@@ -65,8 +68,10 @@ impl EventHandler {
|
||||
command_handler: &mut CommandHandler,
|
||||
form_state: &mut FormState,
|
||||
auth_state: &mut AuthState,
|
||||
login_state: &mut LoginState,
|
||||
register_state: &mut RegisterState,
|
||||
app_state: &mut crate::state::state::AppState,
|
||||
admin_state: &mut AdminState,
|
||||
app_state: &mut AppState,
|
||||
total_count: u64,
|
||||
current_position: &mut u64,
|
||||
) -> Result<EventOutcome, Box<dyn std::error::Error>> {
|
||||
@@ -76,7 +81,7 @@ impl EventHandler {
|
||||
// --- DIALOG MODALITY ---
|
||||
if app_state.ui.dialog.dialog_show {
|
||||
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 {
|
||||
return dialog_result;
|
||||
}
|
||||
@@ -102,7 +107,9 @@ impl EventHandler {
|
||||
config,
|
||||
form_state,
|
||||
app_state,
|
||||
auth_state,
|
||||
login_state,
|
||||
register_state,
|
||||
admin_state,
|
||||
&mut self.command_mode,
|
||||
&mut self.command_input,
|
||||
&mut self.command_message,
|
||||
@@ -117,8 +124,8 @@ impl EventHandler {
|
||||
}
|
||||
UiContext::Login => {
|
||||
message = match index {
|
||||
0 => login::save(auth_state, &mut self.auth_client, app_state).await?,
|
||||
1 => login::back_to_main(auth_state, app_state).await,
|
||||
0 => login::save(auth_state, login_state, &mut self.auth_client, app_state).await?,
|
||||
1 => login::back_to_main(login_state, app_state).await,
|
||||
_ => "Invalid Login Option".to_string(),
|
||||
};
|
||||
}
|
||||
@@ -130,8 +137,8 @@ impl EventHandler {
|
||||
};
|
||||
}
|
||||
UiContext::Admin => {
|
||||
// Assuming handle_admin_selection uses app_state.general.selected_item
|
||||
admin::handle_admin_selection(app_state);
|
||||
|
||||
message = format!("Admin Option {} selected", index);
|
||||
}
|
||||
UiContext::Dialog => {
|
||||
@@ -157,20 +164,20 @@ impl EventHandler {
|
||||
if config.is_enter_edit_mode_after(key_code, modifiers) &&
|
||||
ModeManager::can_enter_edit_mode(current_mode) {
|
||||
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 {
|
||||
form_state.get_current_input()
|
||||
};
|
||||
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 {
|
||||
form_state.current_cursor_pos()
|
||||
};
|
||||
|
||||
if !current_input.is_empty() && current_cursor_pos < current_input.len() {
|
||||
if app_state.ui.show_login || app_state.ui.show_register{
|
||||
auth_state.set_current_cursor_pos(current_cursor_pos + 1);
|
||||
self.ideal_cursor_column = auth_state.current_cursor_pos();
|
||||
login_state.set_current_cursor_pos(current_cursor_pos + 1);
|
||||
self.ideal_cursor_column = login_state.current_cursor_pos();
|
||||
} else {
|
||||
form_state.set_current_cursor_pos(current_cursor_pos + 1);
|
||||
self.ideal_cursor_column = form_state.current_cursor_pos();
|
||||
@@ -203,6 +210,7 @@ impl EventHandler {
|
||||
action,
|
||||
form_state,
|
||||
auth_state,
|
||||
login_state,
|
||||
register_state,
|
||||
grpc_client,
|
||||
&mut self.auth_client,
|
||||
@@ -221,7 +229,7 @@ impl EventHandler {
|
||||
key,
|
||||
config,
|
||||
form_state,
|
||||
auth_state,
|
||||
login_state,
|
||||
register_state,
|
||||
&mut self.key_sequence_tracker,
|
||||
current_position,
|
||||
@@ -240,7 +248,7 @@ impl EventHandler {
|
||||
self.edit_mode_cooldown = true;
|
||||
|
||||
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 {
|
||||
form_state.has_unsaved_changes()
|
||||
};
|
||||
@@ -254,12 +262,12 @@ impl EventHandler {
|
||||
terminal.set_cursor_style(SetCursorStyle::SteadyBlock)?;
|
||||
|
||||
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 {
|
||||
form_state.get_current_input()
|
||||
};
|
||||
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 {
|
||||
form_state.current_cursor_pos()
|
||||
};
|
||||
@@ -267,8 +275,8 @@ impl EventHandler {
|
||||
if !current_input.is_empty() && current_cursor_pos >= current_input.len() {
|
||||
let new_pos = current_input.len() - 1;
|
||||
if app_state.ui.show_login || app_state.ui.show_register{
|
||||
auth_state.set_current_cursor_pos(new_pos);
|
||||
self.ideal_cursor_column = auth_state.current_cursor_pos();
|
||||
login_state.set_current_cursor_pos(new_pos);
|
||||
self.ideal_cursor_column = login_state.current_cursor_pos();
|
||||
} else {
|
||||
form_state.set_current_cursor_pos(new_pos);
|
||||
self.ideal_cursor_column = form_state.current_cursor_pos();
|
||||
@@ -288,6 +296,7 @@ impl EventHandler {
|
||||
action,
|
||||
form_state,
|
||||
auth_state,
|
||||
login_state,
|
||||
register_state,
|
||||
grpc_client,
|
||||
&mut self.auth_client,
|
||||
@@ -305,7 +314,7 @@ impl EventHandler {
|
||||
key,
|
||||
config,
|
||||
form_state,
|
||||
auth_state,
|
||||
login_state,
|
||||
register_state,
|
||||
&mut self.ideal_cursor_column,
|
||||
&mut self.command_message,
|
||||
@@ -324,7 +333,8 @@ impl EventHandler {
|
||||
key,
|
||||
config,
|
||||
app_state,
|
||||
auth_state,
|
||||
login_state,
|
||||
register_state,
|
||||
form_state,
|
||||
&mut self.command_input,
|
||||
&mut self.command_message,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// src/modes/handlers/mode_manager.rs
|
||||
use crate::state::state::AppState;
|
||||
use crate::state::app::state::AppState;
|
||||
use crate::modes::handlers::event::EventHandler;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
use crate::services::grpc_client::GrpcClient;
|
||||
use crate::state::pages::form::FormState;
|
||||
use crate::tui::functions::common::form::SaveOutcome;
|
||||
use crate::state::state::AppState;
|
||||
use crate::state::app::state::AppState;
|
||||
|
||||
pub struct UiService;
|
||||
|
||||
|
||||
3
client/src/state/app.rs
Normal file
3
client/src/state/app.rs
Normal file
@@ -0,0 +1,3 @@
|
||||
// src/state/app.rs
|
||||
|
||||
pub mod state;
|
||||
@@ -27,11 +27,6 @@ pub struct UiState {
|
||||
pub dialog: DialogState,
|
||||
}
|
||||
|
||||
pub struct GeneralState {
|
||||
pub selected_item: usize,
|
||||
pub current_option: usize,
|
||||
}
|
||||
|
||||
pub struct AppState {
|
||||
// Core editor state
|
||||
pub current_dir: String,
|
||||
@@ -43,7 +38,6 @@ pub struct AppState {
|
||||
|
||||
// UI preferences
|
||||
pub ui: UiState,
|
||||
pub general: GeneralState,
|
||||
}
|
||||
|
||||
impl AppState {
|
||||
@@ -59,10 +53,6 @@ impl AppState {
|
||||
selected_profile: None,
|
||||
current_mode: AppMode::General,
|
||||
ui: UiState::default(),
|
||||
general: GeneralState {
|
||||
selected_item: 0,
|
||||
current_option: 0,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// src/state/mod.rs
|
||||
pub mod state;
|
||||
pub mod app;
|
||||
pub mod pages;
|
||||
pub mod canvas_state;
|
||||
|
||||
@@ -2,3 +2,5 @@
|
||||
|
||||
pub mod form;
|
||||
pub mod auth;
|
||||
pub mod admin;
|
||||
pub mod canvas_state;
|
||||
|
||||
38
client/src/state/pages/admin.rs
Normal file
38
client/src/state/pages/admin.rs
Normal file
@@ -0,0 +1,38 @@
|
||||
// src/state/pages/admin.rs
|
||||
|
||||
use ratatui::widgets::ListState;
|
||||
|
||||
#[derive(Default, Clone, Debug)]
|
||||
pub struct AdminState {
|
||||
pub profiles: Vec<String>,
|
||||
pub list_state: ListState,
|
||||
}
|
||||
|
||||
impl AdminState {
|
||||
/// Gets the index of the currently selected item.
|
||||
pub fn get_selected_index(&self) -> Option<usize> {
|
||||
self.list_state.selected()
|
||||
}
|
||||
|
||||
/// Gets the name of the currently selected profile.
|
||||
pub fn get_selected_profile_name(&self) -> Option<&String> {
|
||||
self.list_state.selected().and_then(|i| self.profiles.get(i))
|
||||
}
|
||||
|
||||
/// Populates the profile list and updates/resets the selection.
|
||||
pub fn set_profiles(&mut self, new_profiles: Vec<String>) {
|
||||
let current_selection_index = self.list_state.selected();
|
||||
self.profiles = new_profiles;
|
||||
|
||||
if self.profiles.is_empty() {
|
||||
self.list_state.select(None);
|
||||
} else {
|
||||
let new_selection = match current_selection_index {
|
||||
Some(index) => Some(index.min(self.profiles.len() - 1)),
|
||||
None => Some(0),
|
||||
};
|
||||
self.list_state.select(new_selection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// src/state/pages/auth.rs
|
||||
use crate::state::canvas_state::CanvasState;
|
||||
use crate::state::pages::canvas_state::CanvasState;
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
lazy_static! {
|
||||
@@ -23,11 +23,11 @@ pub struct AuthState {
|
||||
/// Represents the state of the Login form UI
|
||||
#[derive(Default)]
|
||||
pub struct LoginState {
|
||||
pub username: String, // Input field for username/email
|
||||
pub password: String, // Input field for password
|
||||
pub error_message: Option<String>, // Error message specific to login attempt
|
||||
pub current_field: usize, // 0 for username, 1 for password
|
||||
pub current_cursor_pos: usize, // Cursor position within current field
|
||||
pub username: String,
|
||||
pub password: String,
|
||||
pub error_message: Option<String>,
|
||||
pub current_field: usize,
|
||||
pub current_cursor_pos: usize,
|
||||
pub has_unsaved_changes: bool,
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
use crate::config::colors::themes::Theme;
|
||||
use ratatui::layout::Rect;
|
||||
use ratatui::Frame;
|
||||
use crate::state::canvas_state::CanvasState;
|
||||
use crate::state::pages::canvas_state::CanvasState;
|
||||
|
||||
pub struct FormState {
|
||||
pub id: i64,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::state::state::AppState;
|
||||
use crate::state::app::state::AppState;
|
||||
|
||||
pub fn handle_admin_selection(app_state: &mut AppState) {
|
||||
let profiles = &app_state.profile_tree.profiles;
|
||||
|
||||
@@ -2,22 +2,24 @@
|
||||
|
||||
use crate::services::auth::AuthClient;
|
||||
use crate::state::pages::auth::AuthState;
|
||||
use crate::state::state::AppState;
|
||||
use crate::state::canvas_state::CanvasState;
|
||||
use crate::state::pages::auth::LoginState;
|
||||
use crate::state::app::state::AppState;
|
||||
use crate::state::pages::canvas_state::CanvasState;
|
||||
use crate::ui::handlers::context::DialogPurpose;
|
||||
|
||||
/// Attempts to log the user in using the provided credentials via gRPC.
|
||||
/// Updates AuthState and AppState on success or failure.
|
||||
pub async fn save(
|
||||
auth_state: &mut AuthState,
|
||||
login_state: &mut LoginState,
|
||||
auth_client: &mut AuthClient,
|
||||
app_state: &mut AppState,
|
||||
) -> Result<String, Box<dyn std::error::Error>> {
|
||||
let identifier = auth_state.username.clone();
|
||||
let password = auth_state.password.clone();
|
||||
let identifier = login_state.username.clone();
|
||||
let password = login_state.password.clone();
|
||||
|
||||
// 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
|
||||
app_state.hide_dialog();
|
||||
|
||||
@@ -29,7 +31,7 @@ pub async fn save(
|
||||
auth_state.user_id = Some(response.user_id.clone());
|
||||
auth_state.role = Some(response.role.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!(
|
||||
"Login Successful!\n\n\
|
||||
@@ -60,13 +62,8 @@ pub async fn save(
|
||||
vec!["OK".to_string()],
|
||||
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))
|
||||
}
|
||||
@@ -75,27 +72,27 @@ pub async fn save(
|
||||
|
||||
/// Reverts the login form fields to empty and returns to the previous screen (Intro).
|
||||
pub async fn revert(
|
||||
auth_state: &mut AuthState,
|
||||
login_state: &mut LoginState,
|
||||
app_state: &mut AppState,
|
||||
) -> String {
|
||||
// Clear the input fields
|
||||
auth_state.username.clear();
|
||||
auth_state.password.clear();
|
||||
auth_state.error_message = None;
|
||||
auth_state.set_has_unsaved_changes(false);
|
||||
login_state.username.clear();
|
||||
login_state.password.clear();
|
||||
login_state.error_message = None;
|
||||
login_state.set_has_unsaved_changes(false);
|
||||
|
||||
"Login reverted".to_string()
|
||||
}
|
||||
|
||||
pub async fn back_to_main(
|
||||
auth_state: &mut AuthState,
|
||||
login_state: &mut LoginState,
|
||||
app_state: &mut AppState,
|
||||
) -> String {
|
||||
// Clear the input fields
|
||||
auth_state.username.clear();
|
||||
auth_state.password.clear();
|
||||
auth_state.error_message = None;
|
||||
auth_state.set_has_unsaved_changes(false);
|
||||
login_state.username.clear();
|
||||
login_state.password.clear();
|
||||
login_state.error_message = None;
|
||||
login_state.set_has_unsaved_changes(false);
|
||||
|
||||
// Ensure dialog is hidden if revert is called
|
||||
app_state.hide_dialog(); // Uncomment if needed
|
||||
|
||||
@@ -4,8 +4,8 @@ use crate::{
|
||||
services::auth::AuthClient,
|
||||
state::{
|
||||
pages::auth::RegisterState,
|
||||
state::AppState,
|
||||
canvas_state::CanvasState,
|
||||
app::state::AppState,
|
||||
pages::canvas_state::CanvasState,
|
||||
},
|
||||
ui::handlers::context::DialogPurpose,
|
||||
};
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// src/tui/functions/form.rs
|
||||
use crate::state::pages::form::FormState;
|
||||
use crate::services::grpc_client::GrpcClient;
|
||||
use crate::state::canvas_state::CanvasState;
|
||||
use crate::state::pages::canvas_state::CanvasState;
|
||||
|
||||
pub async fn handle_action(
|
||||
action: &str,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::state::state::AppState;
|
||||
use crate::state::app::state::AppState;
|
||||
|
||||
pub fn handle_intro_selection(app_state: &mut AppState, index: usize) { // Add index parameter
|
||||
match index { // Use index directly
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
// src/tui/functions/login.rs
|
||||
use crate::state::pages::auth::AuthState;
|
||||
|
||||
pub async fn handle_action(
|
||||
action: &str,
|
||||
auth_state: &mut AuthState,
|
||||
ideal_cursor_column: &mut usize,
|
||||
) -> Result<String, Box<dyn std::error::Error>> {
|
||||
pub async fn handle_action(action: &str,) -> Result<String, Box<dyn std::error::Error>> {
|
||||
match action {
|
||||
"previous_entry" => {
|
||||
Ok("Previous entry at tui/functions/login.rs not implemented".into())
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// src/ui/handlers/rat_state.rs
|
||||
use crossterm::event::{KeyCode, KeyModifiers};
|
||||
use crate::config::binds::config::Config;
|
||||
use crate::state::state::UiState;
|
||||
use crate::state::app::state::UiState;
|
||||
|
||||
pub struct UiStateHandler;
|
||||
|
||||
|
||||
@@ -14,13 +14,16 @@ 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::LoginState;
|
||||
use crate::state::pages::auth::RegisterState;
|
||||
use crate::state::state::AppState;
|
||||
use crate::state::app::state::AppState;
|
||||
use crate::state::pages::admin::AdminState;
|
||||
|
||||
pub fn render_ui(
|
||||
f: &mut Frame,
|
||||
form_state: &mut FormState,
|
||||
auth_state: &mut AuthState,
|
||||
login_state: &LoginState,
|
||||
register_state: &RegisterState,
|
||||
theme: &Theme,
|
||||
is_edit_mode: bool,
|
||||
@@ -60,9 +63,9 @@ pub fn render_ui(
|
||||
f,
|
||||
main_content_area,
|
||||
theme,
|
||||
auth_state,
|
||||
login_state,
|
||||
app_state,
|
||||
auth_state.current_field < 2
|
||||
login_state.current_field < 2
|
||||
);
|
||||
} else if app_state.ui.show_admin {
|
||||
// Create temporary AdminPanelState for rendering
|
||||
@@ -75,10 +78,9 @@ pub fn render_ui(
|
||||
|
||||
// Set the selected item - FIXED
|
||||
if !admin_state.profiles.is_empty() {
|
||||
let selected_index = std::cmp::min(
|
||||
app_state.general.selected_item,
|
||||
admin_state.profiles.len() - 1
|
||||
);
|
||||
let selected_index = admin_state.get_selected_index()
|
||||
.unwrap_or(0)
|
||||
.min(admin_state.profiles.len() - 1);
|
||||
admin_state.list_state.select(Some(selected_index));
|
||||
}
|
||||
|
||||
|
||||
@@ -7,11 +7,13 @@ use crate::modes::handlers::event::{EventHandler, EventOutcome}; // Import Event
|
||||
use crate::modes::handlers::mode_manager::{AppMode, ModeManager};
|
||||
use crate::services::grpc_client::GrpcClient;
|
||||
use crate::services::ui_service::UiService;
|
||||
use crate::state::canvas_state::CanvasState;
|
||||
use crate::state::pages::auth::AuthState;
|
||||
use crate::state::pages::canvas_state::CanvasState;
|
||||
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::state::AppState;
|
||||
use crate::state::pages::admin::AdminState;
|
||||
use crate::state::app::state::AppState;
|
||||
// Import SaveOutcome
|
||||
use crate::tui::terminal::{EventReader, TerminalCore};
|
||||
use crate::ui::handlers::render::render_ui;
|
||||
@@ -25,6 +27,8 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let theme = Theme::from_str(&config.colors.theme);
|
||||
let mut auth_state = AuthState::default();
|
||||
let mut register_state = RegisterState::default();
|
||||
let mut login_state = LoginState::default();
|
||||
let mut admin_state = AdminState::default();
|
||||
|
||||
// Initialize app_state first
|
||||
let mut app_state = AppState::new()?;
|
||||
@@ -55,6 +59,7 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
|
||||
f,
|
||||
&mut form_state,
|
||||
&mut auth_state,
|
||||
&login_state,
|
||||
®ister_state,
|
||||
&theme,
|
||||
is_edit_mode,
|
||||
@@ -108,14 +113,16 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
|
||||
.handle_event(
|
||||
event,
|
||||
&config,
|
||||
&mut terminal, // Pass terminal mutably
|
||||
&mut terminal,
|
||||
&mut grpc_client,
|
||||
&mut command_handler,
|
||||
&mut form_state,
|
||||
&mut auth_state,
|
||||
&mut login_state,
|
||||
&mut register_state,
|
||||
&mut admin_state,
|
||||
&mut app_state,
|
||||
total_count, // Pass the count *before* potential save
|
||||
total_count,
|
||||
&mut current_position,
|
||||
)
|
||||
.await;
|
||||
@@ -255,14 +262,13 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
|
||||
}
|
||||
} else if app_state.ui.show_login {
|
||||
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() {
|
||||
current_input.len() - 1
|
||||
} else {
|
||||
0
|
||||
};
|
||||
auth_state.current_cursor_pos =
|
||||
event_handler.ideal_cursor_column.min(max_cursor_pos);
|
||||
login_state.current_cursor_pos = event_handler.ideal_cursor_column.min(max_cursor_pos);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user