working perfectly converted ui.rs into smaller pieces
This commit is contained in:
@@ -57,8 +57,8 @@ impl FormState {
|
|||||||
area: Rect,
|
area: Rect,
|
||||||
theme: &Theme,
|
theme: &Theme,
|
||||||
is_edit_mode: bool,
|
is_edit_mode: bool,
|
||||||
total_count: u64,
|
total_count: usize,
|
||||||
current_position: u64,
|
current_position: usize,
|
||||||
) {
|
) {
|
||||||
render_form(
|
render_form(
|
||||||
f,
|
f,
|
||||||
@@ -71,8 +71,8 @@ impl FormState {
|
|||||||
],
|
],
|
||||||
&theme,
|
&theme,
|
||||||
is_edit_mode,
|
is_edit_mode,
|
||||||
total_count,
|
total_count as u64, // Convert to u64 here
|
||||||
current_position,
|
current_position as u64, // Convert to u64 here
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ use std::env;
|
|||||||
pub struct AppState {
|
pub struct AppState {
|
||||||
pub is_saved: bool,
|
pub is_saved: bool,
|
||||||
pub current_dir: String,
|
pub current_dir: String,
|
||||||
pub total_count: u64,
|
pub total_count: usize,
|
||||||
pub current_position: u64,
|
pub current_position: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AppState {
|
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;
|
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;
|
self.current_position = current_position;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,8 +5,12 @@ use crate::client::terminal::AppTerminal;
|
|||||||
use crate::client::colors::Theme;
|
use crate::client::colors::Theme;
|
||||||
use crate::client::config::Config;
|
use crate::client::config::Config;
|
||||||
use ratatui::layout::Rect;
|
use ratatui::layout::Rect;
|
||||||
use super::{FormState, EventHandler, AppState};
|
use crate::client::ui::handlers::{
|
||||||
use super::render::render_ui;
|
event::EventHandler,
|
||||||
|
form::FormState,
|
||||||
|
state::AppState,
|
||||||
|
render::render_ui
|
||||||
|
};
|
||||||
|
|
||||||
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()?;
|
||||||
@@ -19,13 +23,12 @@ 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?;
|
||||||
app_state.update_total_count(total_count.try_into().unwrap());
|
app_state.update_total_count(total_count as usize);
|
||||||
app_state.update_current_position((total_count + 1).try_into().unwrap());
|
app_state.update_current_position((total_count + 1) as usize);
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
// Fetch fresh total count on each iteration
|
|
||||||
let total_count = app_terminal.get_adresar_count().await?;
|
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| {
|
app_terminal.draw(|f| {
|
||||||
render_ui(
|
render_ui(
|
||||||
|
|||||||
Reference in New Issue
Block a user