fixing, nothing works lmao

This commit is contained in:
filipriec
2025-04-18 20:48:39 +02:00
parent 5a029283a1
commit d3fcb23e22
18 changed files with 48 additions and 39 deletions

View File

@@ -2,7 +2,7 @@
use crate::state::pages::add_table::AddTableState;
use crate::state::pages::canvas_state::CanvasState; // Use trait
use crossterm::event::{KeyCode, KeyEvent};
use std::error::Error;
use anyhow::{Context, Result};
#[derive(PartialEq)]
enum CharType {
@@ -134,7 +134,7 @@ pub async fn execute_edit_action(
state: &mut AddTableState,
ideal_cursor_column: &mut usize,
// Add other params like grpc_client if needed for future actions (e.g., validation)
) -> Result<String, Box<dyn Error>> {
) -> Result<String> {
// Use the CanvasState trait methods implemented for AddTableState
match action {
"insert_char" => {

View File

@@ -7,6 +7,7 @@ use crate::state::pages::auth::RegisterState;
use crate::tui::functions::common::form::{revert, save};
use crossterm::event::{KeyCode, KeyEvent};
use std::any::Any;
use anyhow::{Context, Result};
pub async fn execute_common_action<S: CanvasState + Any>(
action: &str,
@@ -14,7 +15,7 @@ pub async fn execute_common_action<S: CanvasState + Any>(
grpc_client: &mut GrpcClient,
current_position: &mut u64,
total_count: u64,
) -> Result<String, Box<dyn std::error::Error>> {
) -> Result<String> {
match action {
"save" | "revert" => {
if !state.has_unsaved_changes() {
@@ -62,7 +63,7 @@ pub async fn execute_edit_action<S: CanvasState + Any + Send>(
key: KeyEvent,
state: &mut S,
ideal_cursor_column: &mut usize,
) -> Result<String, Box<dyn std::error::Error>> {
) -> Result<String> {
match action {
"insert_char" => {
if let KeyCode::Char(c) = key.code {

View File

@@ -8,6 +8,7 @@ use crate::tui::functions::common::form::SaveOutcome;
use crate::modes::handlers::event::EventOutcome;
use crossterm::event::{KeyCode, KeyEvent};
use std::any::Any;
use anyhow::{Context, Result};
pub async fn execute_common_action<S: CanvasState + Any>(
action: &str,
@@ -15,7 +16,7 @@ pub async fn execute_common_action<S: CanvasState + Any>(
grpc_client: &mut GrpcClient,
current_position: &mut u64,
total_count: u64,
) -> Result<EventOutcome, Box<dyn std::error::Error>> {
) -> Result<EventOutcome> {
match action {
"save" | "revert" => {
if !state.has_unsaved_changes() {
@@ -76,7 +77,7 @@ pub async fn execute_edit_action<S: CanvasState>(
key: KeyEvent,
state: &mut S,
ideal_cursor_column: &mut usize,
) -> Result<String, Box<dyn std::error::Error>> {
) -> Result<String> {
match action {
"insert_char" => {
if let KeyCode::Char(c) = key.code {

View File

@@ -3,7 +3,7 @@ use crate::config::binds::key_sequences::KeySequenceTracker;
use crate::state::pages::add_table::AddTableState;
use crate::state::pages::canvas_state::CanvasState; // Use trait for common actions
use crate::state::app::state::AppState;
use std::error::Error;
use anyhow::Result;
// Re-use word navigation helpers if they are public or move them to a common module
// For now, duplicating them here for simplicity. Consider refactoring later.
@@ -74,7 +74,7 @@ pub async fn execute_action(
ideal_cursor_column: &mut usize,
key_sequence_tracker: &mut KeySequenceTracker,
command_message: &mut String, // Keep for potential messages
) -> Result<String, Box<dyn Error>> {
) -> Result<String> {
// Use the CanvasState trait methods implemented for AddTableState
match action {
"move_up" => {

View File

@@ -3,7 +3,7 @@
use crate::config::binds::key_sequences::KeySequenceTracker;
use crate::state::pages::canvas_state::CanvasState;
use crate::state::app::state::AppState;
use std::error::Error;
use anyhow::{Context, Result};
#[derive(PartialEq)]
enum CharType {
@@ -19,7 +19,7 @@ pub async fn execute_action<S: CanvasState>(
ideal_cursor_column: &mut usize,
key_sequence_tracker: &mut KeySequenceTracker,
command_message: &mut String,
) -> Result<String, Box<dyn Error>> {
) -> Result<String> {
match action {
"previous_entry" | "next_entry" => {
key_sequence_tracker.reset();

View File

@@ -2,7 +2,7 @@
use crate::config::binds::key_sequences::KeySequenceTracker;
use crate::state::pages::canvas_state::CanvasState;
use std::error::Error;
use anyhow::Result;
#[derive(PartialEq)]
enum CharType {
@@ -17,7 +17,7 @@ pub async fn execute_action<S: CanvasState>(
ideal_cursor_column: &mut usize,
key_sequence_tracker: &mut KeySequenceTracker,
command_message: &mut String,
) -> Result<String, Box<dyn Error>> {
) -> Result<String> {
match action {
"previous_entry" | "next_entry" => {
key_sequence_tracker.reset();

View File

@@ -7,6 +7,7 @@ use crate::services::grpc_client::GrpcClient;
use crate::services::auth::AuthClient;
use crate::modes::handlers::event::EventOutcome;
use crate::tui::functions::common::form::SaveOutcome;
use anyhow::{Context, Result};
use crate::tui::functions::common::{
form::{save as form_save, revert as form_revert},
login::{save as login_save, revert as login_revert},
@@ -25,14 +26,14 @@ pub async fn handle_core_action(
app_state: &mut AppState,
current_position: &mut u64,
total_count: u64,
) -> Result<EventOutcome, Box<dyn std::error::Error>> {
) -> Result<EventOutcome> {
match action {
"save" => {
if app_state.ui.show_login {
let message = login_save(auth_state, login_state, auth_client, app_state).await?;
let message = login_save(auth_state, login_state, auth_client, app_state).await.context("Login save action failed")?;
Ok(EventOutcome::Ok(message))
} 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.context("Register save_and_quit action failed")?;
Ok(EventOutcome::Ok(message))
} else {
let save_outcome = form_save(
@@ -40,7 +41,7 @@ pub async fn handle_core_action(
grpc_client,
current_position,
total_count,
).await?;
).await.context("Register save action failed")?;
let message = match save_outcome {
SaveOutcome::NoChange => "No changes to save.".to_string(),
SaveOutcome::UpdatedExisting => "Entry updated.".to_string(),
@@ -55,9 +56,9 @@ pub async fn handle_core_action(
},
"save_and_quit" => {
let message = if app_state.ui.show_login {
login_save(auth_state, login_state, auth_client, app_state).await?
login_save(auth_state, login_state, auth_client, app_state).await.context("Login save n quit action failed")?
} 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.context("Register save n quit action failed")?
} else {
let save_outcome = form_save(
form_state,
@@ -87,7 +88,7 @@ pub async fn handle_core_action(
grpc_client,
current_position,
total_count,
).await?;
).await.context("Form revert x action failed")?;
Ok(EventOutcome::Ok(message))
}
},

View File

@@ -11,6 +11,7 @@ use crate::modes::handlers::event::EventOutcome;
use crate::functions::modes::edit::{auth_e, form_e};
use crate::functions::modes::edit::add_table_e;
use crate::state::app::state::AppState;
use anyhow::Result;
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -31,7 +32,7 @@ pub async fn handle_edit_event(
total_count: u64,
grpc_client: &mut GrpcClient,
app_state: &AppState,
) -> Result<EditEventOutcome, Box<dyn std::error::Error>> {
) -> Result<EditEventOutcome> {
// Global command mode check (should ideally be handled before calling this function)
if let Some("enter_command_mode") = config.get_action_for_key_in_mode(
&config.keybindings.global,

View File

@@ -10,6 +10,7 @@ use crate::state::pages::add_table::AddTableState;
use crate::state::app::state::AppState;
use crate::functions::modes::read_only::{auth_ro, form_ro, add_table_ro};
use crossterm::event::KeyEvent;
use anyhow::{Context, Result};
pub async fn handle_read_only_event(
app_state: &mut AppState,
@@ -26,7 +27,7 @@ pub async fn handle_read_only_event(
command_message: &mut String,
edit_mode_cooldown: &mut bool,
ideal_cursor_column: &mut usize,
) -> Result<(bool, String), Box<dyn std::error::Error>> {
) -> Result<(bool, String)> {
if config.is_enter_edit_mode_before(key.code, key.modifiers) {
*edit_mode_cooldown = true;
*command_message = "Entering Edit mode".to_string();

View File

@@ -10,7 +10,7 @@ use crate::tui::terminal::core::TerminalCore;
use crate::tui::functions::common::form::{save, revert};
use crate::modes::handlers::event::EventOutcome;
use crate::tui::functions::common::form::SaveOutcome;
use std::error::Error;
use anyhow::{Context, Result};
pub async fn handle_command_event(
key: KeyEvent,
@@ -26,7 +26,7 @@ pub async fn handle_command_event(
terminal: &mut TerminalCore,
current_position: &mut u64,
total_count: u64,
) -> Result<EventOutcome, Box<dyn Error>> {
) -> Result<EventOutcome> {
// Exit command mode (via configurable keybinding)
if config.is_exit_command_mode(key.code, key.modifiers) {
command_input.clear();
@@ -84,7 +84,7 @@ async fn process_command(
terminal: &mut TerminalCore,
current_position: &mut u64,
total_count: u64,
) -> Result<EventOutcome, Box<dyn Error>> {
) -> Result<EventOutcome> {
// Clone the trimmed command to avoid borrow issues
let command = command_input.trim().to_string();
if command.is_empty() {

View File

@@ -3,6 +3,7 @@ use crate::tui::terminal::core::TerminalCore;
use crate::state::app::state::AppState;
use crate::state::pages::{form::FormState, auth::LoginState, auth::RegisterState};
use crate::state::pages::canvas_state::CanvasState;
use anyhow::{Context, Result};
pub struct CommandHandler;
@@ -19,7 +20,7 @@ impl CommandHandler {
form_state: &FormState,
login_state: &LoginState,
register_state: &RegisterState,
) -> Result<(bool, String), Box<dyn std::error::Error>> {
) -> Result<(bool, String)> {
match action {
"quit" => self.handle_quit(terminal, app_state, form_state, login_state, register_state).await,
"force_quit" => self.handle_force_quit(terminal).await,
@@ -35,7 +36,7 @@ impl CommandHandler {
form_state: &FormState,
login_state: &LoginState,
register_state: &RegisterState,
) -> Result<(bool, String), Box<dyn std::error::Error>> {
) -> Result<(bool, String)> {
// Use actual unsaved changes state instead of is_saved flag
let has_unsaved = if app_state.ui.show_login {
login_state.has_unsaved_changes()
@@ -56,7 +57,7 @@ impl CommandHandler {
async fn handle_force_quit(
&self,
terminal: &mut TerminalCore,
) -> Result<(bool, String), Box<dyn std::error::Error>> {
) -> Result<(bool, String)> {
terminal.cleanup()?;
Ok((true, "Force exiting without saving.".into()))
}
@@ -64,7 +65,7 @@ impl CommandHandler {
async fn handle_save_quit(
&mut self,
terminal: &mut TerminalCore,
) -> Result<(bool, String), Box<dyn std::error::Error>> {
) -> Result<(bool, String)> {
terminal.cleanup()?;
Ok((true, "State saved. Exiting.".into()))
}

View File

@@ -10,6 +10,7 @@ use crate::state::pages::admin::AdminState;
use crate::modes::handlers::event::EventOutcome;
use crate::tui::functions::common::{login, register};
use crate::tui::functions::common::add_table::handle_delete_selected_columns;
use anyhow::{Context, Result};
/// Handles key events specifically when a dialog is active.
/// Returns Some(Result<EventOutcome, Error>) if the event was handled (consumed),
@@ -22,7 +23,7 @@ pub async fn handle_dialog_event(
register_state: &mut RegisterState,
buffer_state: &mut BufferState,
admin_state: &mut AdminState,
) -> Option<Result<EventOutcome, Box<dyn std::error::Error>>> {
) -> Option<Result<EventOutcome>> {
if let Event::Key(key) = event {
// Always allow Esc to dismiss
if key.code == KeyCode::Esc {

View File

@@ -11,6 +11,7 @@ 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 anyhow::{Context, Result};
pub async fn handle_navigation_event(
key: KeyEvent,
@@ -24,7 +25,7 @@ pub async fn handle_navigation_event(
command_mode: &mut bool,
command_input: &mut String,
command_message: &mut String,
) -> Result<EventOutcome, Box<dyn std::error::Error>> {
) -> Result<EventOutcome> {
if let Some(action) = config.get_general_action(key.code, key.modifiers) {
match action {
"move_up" => {

View File

@@ -280,7 +280,7 @@ impl EventHandler {
}
UiContext::Register => {
match index {
0 => register::save(register_state, &mut self.auth_client, app_state).await?,
0 => register::save(register_state, &mut self.auth_client, app_state).await.context("Register save action failed")?,
1 => register::back_to_login(register_state, app_state, buffer_state).await,
_ => "Invalid Login Option".to_string(),
}
@@ -534,7 +534,7 @@ impl EventHandler {
}
Err(e) => {
// Handle error from the edit handler
return Err(e);
return Err(e.into());
}
}
}, // End AppMode::Edit

View File

@@ -12,7 +12,7 @@ impl UiService {
pub async fn initialize_app_state(
grpc_client: &mut GrpcClient,
app_state: &mut AppState,
) -> Result<Vec<String>, Box<dyn std::error::Error>> {
) -> Result<Vec<String>> {
// Fetch profile tree
let profile_tree = grpc_client.get_profile_tree().await.context("Failed to get profile tree")?;
app_state.profile_tree = profile_tree;
@@ -34,7 +34,7 @@ impl UiService {
grpc_client: &mut GrpcClient,
app_state: &mut AppState,
) -> Result<()> {
let total_count = grpc_client.get_adresar_count().await.await.context("Failed to get adresar count")?;
let total_count = grpc_client.get_adresar_count().await.context("Failed to get adresar count")?;
app_state.update_total_count(total_count);
app_state.update_current_position(total_count.saturating_add(1)); // Start in new entry mode
Ok(())

View File

@@ -3,6 +3,7 @@
use crate::services::grpc_client::GrpcClient;
use crate::state::pages::form::FormState;
use common::proto::multieko2::adresar::{PostAdresarRequest, PutAdresarRequest};
use anyhow::{Context, Result};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SaveOutcome {
@@ -17,7 +18,7 @@ pub async fn save(
grpc_client: &mut GrpcClient,
current_position: &mut u64,
total_count: u64,
) -> Result<SaveOutcome, Box<dyn std::error::Error>> { // <-- Return SaveOutcome
) -> Result<SaveOutcome> { // <-- Return SaveOutcome
if !form_state.has_unsaved_changes {
return Ok(SaveOutcome::NoChange); // Early exit if no changes
}
@@ -78,7 +79,7 @@ pub async fn revert(
grpc_client: &mut GrpcClient,
current_position: &mut u64,
total_count: u64,
) -> Result<String, Box<dyn std::error::Error>> {
) -> Result<String> {
let is_new = *current_position == total_count + 1;
if is_new {

View File

@@ -8,6 +8,7 @@ use crate::state::{
};
use crate::ui::handlers::context::DialogPurpose;
use crate::state::app::buffer::{AppView, BufferState};
use anyhow::{Context, Result};
/// Attempts to register the user using the provided details via gRPC.
/// Updates RegisterState and AppState on success or failure.
@@ -15,7 +16,7 @@ pub async fn save(
register_state: &mut RegisterState,
auth_client: &mut AuthClient,
app_state: &mut AppState,
) -> Result<String, Box<dyn std::error::Error>> {
) -> Result<String> {
let username = register_state.username.clone();
let email = register_state.email.clone();
// Handle optional passwords: send None if empty, Some(value) otherwise

View File

@@ -57,8 +57,7 @@ pub async fn run_ui() -> Result<()> {
let mut form_state = FormState::new(column_names);
// Fetch the total count of Adresar entries
UiService::initialize_adresar_count(&mut grpc_client, &mut app_state).await
.await?;
UiService::initialize_adresar_count(&mut grpc_client, &mut app_state).await?;
form_state.reset_to_empty();
// --- FPS Calculation State ---