diff --git a/client/src/modes/handlers/read_only.rs b/client/src/modes/handlers/read_only.rs deleted file mode 100644 index d7d56a6..0000000 --- a/client/src/modes/handlers/read_only.rs +++ /dev/null @@ -1,17 +0,0 @@ -// src/modes/handlers/read_only.rs -use async_trait::async_trait; -use crate::tui::terminal::grpc_client::GrpcClient; - -#[async_trait] -pub trait ReadOnlyHandler { - async fn handle_read_only_action( - &mut self, - action: &str, - grpc_client: &mut GrpcClient, - current_position: &mut u64, - total_count: u64, - ) -> Result>; - - // Add this method - fn adjust_cursor_position(&mut self, ideal_column: &mut usize); -} diff --git a/client/src/state/pages/form.rs b/client/src/state/pages/form.rs index 8d310a8..b7203e4 100644 --- a/client/src/state/pages/form.rs +++ b/client/src/state/pages/form.rs @@ -15,68 +15,6 @@ pub struct FormState { pub current_cursor_pos: usize, } -#[async_trait::async_trait] -impl ReadOnlyHandler for FormState { - async fn handle_read_only_action( - &mut self, - action: &str, - grpc_client: &mut GrpcClient, - current_position: &mut u64, - total_count: u64, - ) -> Result> { - match action { - "previous_entry" => { - let new_position = current_position.saturating_sub(1); - if new_position >= 1 { - *current_position = new_position; - let response = grpc_client.get_adresar_by_position(*current_position).await?; - self.update_from_response(response); - Ok(format!("Loaded entry {}", *current_position)) - } else { - Ok("Already at first entry".into()) - } - }, - "next_entry" => { - if *current_position < total_count { - *current_position += 1; - let response = grpc_client.get_adresar_by_position(*current_position).await?; - self.update_from_response(response); - Ok(format!("Loaded entry {}", *current_position)) - } else { - self.reset_to_empty(); - Ok("New entry mode".into()) - } - }, - "move_down" => { - self.current_field = (self.current_field + 1) % self.fields.len(); - let current_input = self.get_current_input(); - let max_pos = current_input.len().saturating_sub(1); - self.current_cursor_pos = self.current_cursor_pos.min(max_pos); - Ok("".into()) - }, - "move_up" => { - if self.current_field == 0 { - self.current_field = self.fields.len() - 1; - } else { - self.current_field = self.current_field.saturating_sub(1); - } - let current_input = self.get_current_input(); - let max_pos = current_input.len().saturating_sub(1); - self.current_cursor_pos = self.current_cursor_pos.min(max_pos); - Ok("".into()) - }, - _ => Ok(format!("Unknown action: {}", action)) - } - } - - fn adjust_cursor_position(&mut self, ideal_column: &mut usize) { - let current_input = self.get_current_input(); - let max_pos = current_input.len().saturating_sub(1); - self.current_cursor_pos = (*ideal_column).min(max_pos); - *ideal_column = self.current_cursor_pos; - } -} - impl FormState { /// Create a new FormState with dynamic fields. pub fn new(fields: Vec) -> Self {