compiled, needs other fixes
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
use crate::state::pages::form::FormState;
|
||||
use crate::services::grpc_client::GrpcClient;
|
||||
use crate::state::pages::canvas_state::CanvasState;
|
||||
use crate::services::ui_service::UiService;
|
||||
use anyhow::{anyhow, Result};
|
||||
|
||||
pub async fn handle_action(
|
||||
@@ -12,8 +13,7 @@ pub async fn handle_action(
|
||||
total_count: u64,
|
||||
ideal_cursor_column: &mut usize,
|
||||
) -> Result<String> {
|
||||
// TODO store unsaved changes without deleting form state values
|
||||
// First check for unsaved changes in both cases
|
||||
// Check for unsaved changes in both cases
|
||||
if form_state.has_unsaved_changes() {
|
||||
return Ok(
|
||||
"Unsaved changes. Save (Ctrl+S) or Revert (Ctrl+R) before navigating."
|
||||
@@ -23,57 +23,43 @@ pub async fn handle_action(
|
||||
|
||||
match action {
|
||||
"previous_entry" => {
|
||||
let new_position = current_position.saturating_sub(1);
|
||||
let new_position = form_state.current_position.saturating_sub(1);
|
||||
if new_position >= 1 {
|
||||
form_state.current_position = new_position;
|
||||
*current_position = new_position;
|
||||
let response = grpc_client.get_adresar_by_position(*current_position).await?;
|
||||
|
||||
// Direct field assignments
|
||||
form_state.id = response.id;
|
||||
form_state.values = vec![
|
||||
response.firma, response.kz, response.drc,
|
||||
response.ulica, response.psc, response.mesto,
|
||||
response.stat, response.banka, response.ucet,
|
||||
response.skladm, response.ico, response.kontakt,
|
||||
response.telefon, response.skladu, response.fax,
|
||||
];
|
||||
|
||||
let current_input = form_state.get_current_input();
|
||||
let max_cursor_pos = if !current_input.is_empty() {
|
||||
current_input.len() - 1
|
||||
} else { 0 };
|
||||
form_state.current_cursor_pos = std::cmp::min(*ideal_cursor_column, max_cursor_pos);
|
||||
form_state.has_unsaved_changes = false;
|
||||
|
||||
Ok(format!("Loaded form entry {}", *current_position))
|
||||
} else {
|
||||
Ok("Already at first form entry".into())
|
||||
}
|
||||
}
|
||||
"next_entry" => {
|
||||
if *current_position <= total_count {
|
||||
*current_position += 1;
|
||||
if *current_position <= total_count {
|
||||
let response = grpc_client.get_adresar_by_position(*current_position).await?;
|
||||
|
||||
// Direct field assignments
|
||||
form_state.id = response.id;
|
||||
form_state.values = vec![
|
||||
response.firma, response.kz, response.drc,
|
||||
response.ulica, response.psc, response.mesto,
|
||||
response.stat, response.banka, response.ucet,
|
||||
response.skladm, response.ico, response.kontakt,
|
||||
response.telefon, response.skladu, response.fax,
|
||||
];
|
||||
|
||||
|
||||
if new_position <= form_state.total_count {
|
||||
let load_message = UiService::load_table_data_by_position(grpc_client, form_state).await?;
|
||||
|
||||
let current_input = form_state.get_current_input();
|
||||
let max_cursor_pos = if !current_input.is_empty() {
|
||||
current_input.len() - 1
|
||||
} else { 0 };
|
||||
form_state.current_cursor_pos = std::cmp::min(*ideal_cursor_column, max_cursor_pos);
|
||||
form_state.has_unsaved_changes = false;
|
||||
|
||||
Ok(format!("Loaded form entry {}", *current_position))
|
||||
form_state.current_cursor_pos = (*ideal_cursor_column).min(max_cursor_pos);
|
||||
|
||||
Ok(load_message)
|
||||
} else {
|
||||
Ok(format!("Moved to position {}", new_position))
|
||||
}
|
||||
} else {
|
||||
Ok("Already at first position".into())
|
||||
}
|
||||
}
|
||||
"next_entry" => {
|
||||
if form_state.current_position <= form_state.total_count {
|
||||
form_state.current_position += 1;
|
||||
*current_position = form_state.current_position;
|
||||
|
||||
if form_state.current_position <= form_state.total_count {
|
||||
let load_message = UiService::load_table_data_by_position(grpc_client, form_state).await?;
|
||||
|
||||
let current_input = form_state.get_current_input();
|
||||
let max_cursor_pos = if !current_input.is_empty() {
|
||||
current_input.len() - 1
|
||||
} else { 0 };
|
||||
form_state.current_cursor_pos = (*ideal_cursor_column).min(max_cursor_pos);
|
||||
|
||||
Ok(load_message)
|
||||
} else {
|
||||
form_state.reset_to_empty();
|
||||
form_state.current_field = 0;
|
||||
@@ -86,6 +72,5 @@ pub async fn handle_action(
|
||||
}
|
||||
}
|
||||
_ => Err(anyhow!("Unknown form action: {}", action))
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user