working perfectly converted ui.rs into smaller pieces

This commit is contained in:
filipriec
2025-02-18 23:48:46 +01:00
parent 054d647d83
commit cb1004c9c7
3 changed files with 17 additions and 14 deletions

View File

@@ -57,8 +57,8 @@ impl FormState {
area: Rect,
theme: &Theme,
is_edit_mode: bool,
total_count: u64,
current_position: u64,
total_count: usize,
current_position: usize,
) {
render_form(
f,
@@ -71,8 +71,8 @@ impl FormState {
],
&theme,
is_edit_mode,
total_count,
current_position,
total_count as u64, // Convert to u64 here
current_position as u64, // Convert to u64 here
);
}
}

View File

@@ -5,8 +5,8 @@ use std::env;
pub struct AppState {
pub is_saved: bool,
pub current_dir: String,
pub total_count: u64,
pub current_position: u64,
pub total_count: usize,
pub current_position: usize,
}
impl AppState {
@@ -22,11 +22,11 @@ impl AppState {
})
}
pub fn update_total_count(&mut self, total_count: u64) {
pub fn update_total_count(&mut self, total_count: usize) {
self.total_count = total_count;
}
pub fn update_current_position(&mut self, current_position: u64) {
pub fn update_current_position(&mut self, current_position: usize) {
self.current_position = current_position;
}
}

View File

@@ -5,8 +5,12 @@ use crate::client::terminal::AppTerminal;
use crate::client::colors::Theme;
use crate::client::config::Config;
use ratatui::layout::Rect;
use super::{FormState, EventHandler, AppState};
use super::render::render_ui;
use crate::client::ui::handlers::{
event::EventHandler,
form::FormState,
state::AppState,
render::render_ui
};
pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
let config = Config::load()?;
@@ -19,13 +23,12 @@ 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.try_into().unwrap());
app_state.update_current_position((total_count + 1).try_into().unwrap());
app_state.update_total_count(total_count as usize);
app_state.update_current_position((total_count + 1) as usize);
loop {
// Fetch fresh total count on each iteration
let total_count = app_terminal.get_adresar_count().await?;
app_state.update_total_count(total_count.try_into().unwrap());
app_state.update_total_count(total_count as usize);
app_terminal.draw(|f| {
render_ui(