count properly works
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
// src/client/components/form.rs
|
// src/client/components/form.rs
|
||||||
|
|
||||||
use ratatui::{
|
use ratatui::{
|
||||||
widgets::{Paragraph, Block, Borders},
|
widgets::{Paragraph, Block, Borders},
|
||||||
layout::{Layout, Constraint, Direction, Rect, Margin, Alignment},
|
layout::{Layout, Constraint, Direction, Rect, Margin, Alignment},
|
||||||
@@ -17,7 +18,7 @@ pub fn render_form(
|
|||||||
theme: &Theme,
|
theme: &Theme,
|
||||||
is_edit_mode: bool,
|
is_edit_mode: bool,
|
||||||
total_count: u64, // Add total count
|
total_count: u64, // Add total count
|
||||||
current_id: u64, // Add current ID
|
current_position: u64, // Add current position
|
||||||
) {
|
) {
|
||||||
// Create Adresar card
|
// Create Adresar card
|
||||||
let adresar_card = Block::default()
|
let adresar_card = Block::default()
|
||||||
@@ -38,17 +39,17 @@ pub fn render_form(
|
|||||||
let main_layout = Layout::default()
|
let main_layout = Layout::default()
|
||||||
.direction(Direction::Vertical)
|
.direction(Direction::Vertical)
|
||||||
.constraints([
|
.constraints([
|
||||||
Constraint::Length(1), // For count and ID
|
Constraint::Length(1), // For count and position
|
||||||
Constraint::Min(1), // For form fields
|
Constraint::Min(1), // For form fields
|
||||||
])
|
])
|
||||||
.split(inner_area);
|
.split(inner_area);
|
||||||
|
|
||||||
// Render the count and ID at the very top
|
// Render the count and position at the very top
|
||||||
let count_id_text = format!("Total: {} | Current: {}", total_count, current_id);
|
let count_position_text = format!("Total: {} | Current Position: {}", total_count, current_position);
|
||||||
let count_id_paragraph = Paragraph::new(count_id_text)
|
let count_position_paragraph = Paragraph::new(count_position_text)
|
||||||
.style(Style::default().fg(theme.fg))
|
.style(Style::default().fg(theme.fg))
|
||||||
.alignment(Alignment::Left);
|
.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
|
// Split the remaining space into label and input columns
|
||||||
let columns = Layout::default()
|
let columns = Layout::default()
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
// src/client/ui.rs
|
// src/client/ui.rs
|
||||||
|
|
||||||
use crossterm::event::{Event, KeyCode, KeyModifiers};
|
use crossterm::event::{Event, KeyCode, KeyModifiers};
|
||||||
use crate::client::terminal::AppTerminal;
|
use crate::client::terminal::AppTerminal;
|
||||||
use crate::client::components::{render_command_line, render_form, render_preview_card, render_status_line};
|
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 std::env;
|
||||||
use crate::proto::multieko2::PostAdresarRequest;
|
use crate::proto::multieko2::PostAdresarRequest;
|
||||||
|
|
||||||
|
|
||||||
pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
|
pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let config = Config::load()?;
|
let config = Config::load()?;
|
||||||
let mut app_terminal = AppTerminal::new().await?;
|
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
|
// Fetch the total count of Adresar entries
|
||||||
let total_count = app_terminal.get_adresar_count().await?;
|
let total_count = app_terminal.get_adresar_count().await?;
|
||||||
|
|
||||||
// Fetch the current Adresar entry by position (e.g., position 1)
|
// Track the current position in the database sequence
|
||||||
let current_position = 1; // You can change this dynamically based on user input
|
let mut current_position = total_count + 1; // Start at the next position for new entries
|
||||||
let current_adresar = app_terminal.get_adresar_by_position(current_position).await?;
|
|
||||||
let current_id = current_adresar.id as u64;
|
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
// Fetch fresh total count on each iteration
|
||||||
|
let total_count = app_terminal.get_adresar_count().await?;
|
||||||
|
|
||||||
app_terminal.draw(|f| {
|
app_terminal.draw(|f| {
|
||||||
let root = Layout::default()
|
let root = Layout::default()
|
||||||
.direction(Direction::Vertical)
|
.direction(Direction::Vertical)
|
||||||
@@ -90,7 +91,7 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
&theme,
|
&theme,
|
||||||
is_edit_mode,
|
is_edit_mode,
|
||||||
total_count, // Pass total count
|
total_count, // Pass total count
|
||||||
current_id, // Pass current ID
|
current_position, // Pass current position
|
||||||
);
|
);
|
||||||
|
|
||||||
// Right panel - Preview Card
|
// 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);
|
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()? {
|
if let Event::Key(key) = app_terminal.read_event()? {
|
||||||
// Handle enter/edit mode keys
|
// Handle enter/edit mode keys
|
||||||
if !is_edit_mode && config.is_enter_edit_mode(key.code, key.modifiers) {
|
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_mode = false;
|
||||||
command_input.clear();
|
command_input.clear();
|
||||||
|
|
||||||
|
// Update current position after saving
|
||||||
|
if action == "save" && is_saved {
|
||||||
|
current_position = total_count + 1;
|
||||||
|
}
|
||||||
|
|
||||||
if should_exit {
|
if should_exit {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user