count properly works

This commit is contained in:
filipriec
2025-02-18 21:59:20 +01:00
parent 3b274e13d5
commit 84f5ec5c4c
2 changed files with 20 additions and 13 deletions

View File

@@ -1,4 +1,5 @@
// src/client/components/form.rs
use ratatui::{
widgets::{Paragraph, Block, Borders},
layout::{Layout, Constraint, Direction, Rect, Margin, Alignment},
@@ -17,7 +18,7 @@ pub fn render_form(
theme: &Theme,
is_edit_mode: bool,
total_count: u64, // Add total count
current_id: u64, // Add current ID
current_position: u64, // Add current position
) {
// Create Adresar card
let adresar_card = Block::default()
@@ -38,17 +39,17 @@ pub fn render_form(
let main_layout = Layout::default()
.direction(Direction::Vertical)
.constraints([
Constraint::Length(1), // For count and ID
Constraint::Length(1), // For count and position
Constraint::Min(1), // For form fields
])
.split(inner_area);
// Render the count and ID at the very top
let count_id_text = format!("Total: {} | Current: {}", total_count, current_id);
let count_id_paragraph = Paragraph::new(count_id_text)
// Render the count and position at the very top
let count_position_text = format!("Total: {} | Current Position: {}", total_count, current_position);
let count_position_paragraph = Paragraph::new(count_position_text)
.style(Style::default().fg(theme.fg))
.alignment(Alignment::Left);
f.render_widget(count_id_paragraph, main_layout[0]);
f.render_widget(count_position_paragraph, main_layout[0]);
// Split the remaining space into label and input columns
let columns = Layout::default()

View File

@@ -1,4 +1,5 @@
// src/client/ui.rs
use crossterm::event::{Event, KeyCode, KeyModifiers};
use crate::client::terminal::AppTerminal;
use crate::client::components::{render_command_line, render_form, render_preview_card, render_status_line};
@@ -8,7 +9,6 @@ use ratatui::layout::{Constraint, Direction, Layout};
use std::env;
use crate::proto::multieko2::PostAdresarRequest;
pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
let config = Config::load()?;
let mut app_terminal = AppTerminal::new().await?;
@@ -55,12 +55,13 @@ 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?;
// Fetch the current Adresar entry by position (e.g., position 1)
let current_position = 1; // You can change this dynamically based on user input
let current_adresar = app_terminal.get_adresar_by_position(current_position).await?;
let current_id = current_adresar.id as u64;
// Track the current position in the database sequence
let mut current_position = total_count + 1; // Start at the next position for new entries
loop {
// Fetch fresh total count on each iteration
let total_count = app_terminal.get_adresar_count().await?;
app_terminal.draw(|f| {
let root = Layout::default()
.direction(Direction::Vertical)
@@ -90,7 +91,7 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
&theme,
is_edit_mode,
total_count, // Pass total count
current_id, // Pass current ID
current_position, // Pass current position
);
// Right panel - Preview Card
@@ -110,7 +111,7 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
render_command_line(f, root[2], &command_input, command_mode, &theme, &command_message);
})?;
// Event handling (unchanged)
// Event handling
if let Event::Key(key) = app_terminal.read_event()? {
// Handle enter/edit mode keys
if !is_edit_mode && config.is_enter_edit_mode(key.code, key.modifiers) {
@@ -201,6 +202,11 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
command_mode = false;
command_input.clear();
// Update current position after saving
if action == "save" && is_saved {
current_position = total_count + 1;
}
if should_exit {
return Ok(());
}