From 78e76f8eb3f3f15ed7b10ccfc995789d8b9c2cb0 Mon Sep 17 00:00:00 2001 From: filipriec Date: Wed, 19 Feb 2025 14:05:09 +0100 Subject: [PATCH] save split config that works --- src/client/colors.rs | 2 +- src/client/components1/handlers/form.rs | 12 ++++++++---- src/client/ui/handlers/event.rs | 4 ++-- src/client/ui/handlers/form.rs | 10 ++++++---- src/client/ui/handlers/render.rs | 4 ++-- src/client/ui/handlers/state.rs | 8 ++++---- src/client/ui/handlers/ui.rs | 6 +++--- 7 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/client/colors.rs b/src/client/colors.rs index 7730b6c..698d431 100644 --- a/src/client/colors.rs +++ b/src/client/colors.rs @@ -6,7 +6,7 @@ pub struct Theme { pub bg: Color, pub fg: Color, pub accent: Color, - pub secondary: Color, // Add this field + pub secondary: Color, pub highlight: Color, pub warning: Color, pub border: Color, diff --git a/src/client/components1/handlers/form.rs b/src/client/components1/handlers/form.rs index 8efc4af..68cf162 100644 --- a/src/client/components1/handlers/form.rs +++ b/src/client/components1/handlers/form.rs @@ -17,8 +17,8 @@ pub fn render_form( inputs: &[&String], theme: &Theme, is_edit_mode: bool, - total_count: u64, // Add total count - current_position: u64, // Add current position + total_count: u64, + current_position: u64, ) { // Create Adresar card let adresar_card = Block::default() @@ -61,9 +61,13 @@ pub fn render_form( let input_container = Block::default() .borders(Borders::ALL) .border_style(if is_edit_mode { - Style::default().fg(theme.accent) + if form_state.has_unsaved_changes { + Style::default().fg(theme.warning) // Red color + } else { + Style::default().fg(theme.accent) // Blue color + } } else { - Style::default().fg(theme.secondary) + Style::default().fg(theme.secondary) // Yellow color }) .style(Style::default().bg(theme.bg)); diff --git a/src/client/ui/handlers/event.rs b/src/client/ui/handlers/event.rs index b8cdf05..969c6bb 100644 --- a/src/client/ui/handlers/event.rs +++ b/src/client/ui/handlers/event.rs @@ -32,8 +32,8 @@ impl EventHandler { app_terminal: &mut AppTerminal, form_state: &mut FormState, is_saved: &mut bool, - total_count: usize, - current_position: &mut usize, + total_count: u64, + current_position: &mut u64, ) -> Result<(bool, String), Box> { if let Event::Key(key) = event { if !self.is_edit_mode && config.is_enter_edit_mode(key.code, key.modifiers) { diff --git a/src/client/ui/handlers/form.rs b/src/client/ui/handlers/form.rs index 7125f0d..8725dc8 100644 --- a/src/client/ui/handlers/form.rs +++ b/src/client/ui/handlers/form.rs @@ -23,6 +23,7 @@ pub struct FormState { pub fax: String, pub current_field: usize, pub fields: Vec<&'static str>, + pub has_unsaved_changes: bool, } impl FormState { @@ -44,6 +45,7 @@ impl FormState { skladu: String::new(), fax: String::new(), current_field: 0, + has_unsaved_changes: false, fields: vec![ "Firma", "KZ", "DRC", "Ulica", "PSC", "Mesto", "Stat", "Banka", "Ucet", "Skladm", "ICO", "Kontakt", "Telefon", "Skladu", "Fax", @@ -57,8 +59,8 @@ impl FormState { area: Rect, theme: &Theme, is_edit_mode: bool, - total_count: usize, - current_position: usize, + total_count: u64, + current_position: u64, ) { render_form( f, @@ -71,8 +73,8 @@ impl FormState { ], &theme, is_edit_mode, - total_count as u64, // Convert to u64 here - current_position as u64, // Convert to u64 here + total_count, + current_position, ); } } diff --git a/src/client/ui/handlers/render.rs b/src/client/ui/handlers/render.rs index dba6f51..94d4d07 100644 --- a/src/client/ui/handlers/render.rs +++ b/src/client/ui/handlers/render.rs @@ -11,8 +11,8 @@ pub fn render_ui( form_state: &mut FormState, theme: &Theme, is_edit_mode: bool, - total_count: usize, - current_position: usize, + total_count: u64, + current_position: u64, current_dir: &str, command_input: &str, command_mode: bool, diff --git a/src/client/ui/handlers/state.rs b/src/client/ui/handlers/state.rs index 2bbf14b..d1330ba 100644 --- a/src/client/ui/handlers/state.rs +++ b/src/client/ui/handlers/state.rs @@ -5,8 +5,8 @@ use std::env; pub struct AppState { pub is_saved: bool, pub current_dir: String, - pub total_count: usize, - pub current_position: usize, + pub total_count: u64, + pub current_position: u64, } impl AppState { @@ -22,11 +22,11 @@ impl AppState { }) } - pub fn update_total_count(&mut self, total_count: usize) { + pub fn update_total_count(&mut self, total_count: u64) { self.total_count = total_count; } - pub fn update_current_position(&mut self, current_position: usize) { + pub fn update_current_position(&mut self, current_position: u64) { self.current_position = current_position; } } diff --git a/src/client/ui/handlers/ui.rs b/src/client/ui/handlers/ui.rs index 00f26e6..a953530 100644 --- a/src/client/ui/handlers/ui.rs +++ b/src/client/ui/handlers/ui.rs @@ -23,12 +23,12 @@ pub async fn run_ui() -> Result<(), Box> { // Fetch the total count of Adresar entries let total_count = app_terminal.get_adresar_count().await?; - app_state.update_total_count(total_count as usize); - app_state.update_current_position((total_count + 1) as usize); + app_state.update_total_count(total_count); + app_state.update_current_position(total_count + 1); loop { let total_count = app_terminal.get_adresar_count().await?; - app_state.update_total_count(total_count as usize); + app_state.update_total_count(total_count); app_terminal.draw(|f| { render_ui(