attempt to clear out the terminal on a new post request, not working properly yet, fixing it all now
This commit is contained in:
@@ -82,4 +82,22 @@ impl FormState {
|
||||
current_position,
|
||||
);
|
||||
}
|
||||
pub fn reset_to_empty(&mut self) {
|
||||
self.firma.clear();
|
||||
self.kz.clear();
|
||||
self.drc.clear();
|
||||
self.ulica.clear();
|
||||
self.psc.clear();
|
||||
self.mesto.clear();
|
||||
self.stat.clear();
|
||||
self.banka.clear();
|
||||
self.ucet.clear();
|
||||
self.skladm.clear();
|
||||
self.ico.clear();
|
||||
self.kontakt.clear();
|
||||
self.telefon.clear();
|
||||
self.skladu.clear();
|
||||
self.fax.clear();
|
||||
self.has_unsaved_changes = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,8 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// Fetch the total count of Adresar entries
|
||||
let total_count = app_terminal.get_adresar_count().await?;
|
||||
app_state.update_total_count(total_count);
|
||||
app_state.update_current_position(total_count + 1);
|
||||
app_state.update_current_position(total_count.saturating_add(1)); // Start in new entry mode
|
||||
form_state.reset_to_empty();
|
||||
|
||||
// Load initial data if there are existing entries
|
||||
if total_count > 0 {
|
||||
@@ -67,10 +68,11 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// Handle position changes and update form state
|
||||
if !event_handler.is_edit_mode {
|
||||
if app_state.current_position > total_count {
|
||||
app_state.current_position = total_count;
|
||||
}
|
||||
|
||||
if app_state.current_position >= 1 && app_state.current_position <= total_count {
|
||||
// New entry - reset form
|
||||
form_state.reset_to_empty();
|
||||
form_state.current_field = 0;
|
||||
} else if app_state.current_position >= 1 && app_state.current_position <= total_count {
|
||||
// Existing entry - load data
|
||||
match app_terminal
|
||||
.get_adresar_by_position(app_state.current_position)
|
||||
.await
|
||||
@@ -83,6 +85,9 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
|
||||
format!("Error loading entry: {}", e);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Invalid position - reset to first entry
|
||||
app_state.current_position = 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user