From 054d647d83dbe364489e29ae7513776f322027d0 Mon Sep 17 00:00:00 2001 From: filipriec Date: Tue, 18 Feb 2025 23:09:29 +0100 Subject: [PATCH] not working, working on redesigning ui.rs --- src/client/ui/handlers/event.rs | 1 + src/client/ui/handlers/form.rs | 10 ++++++- src/client/ui/handlers/render.rs | 1 + src/client/ui/handlers/state.rs | 8 +++--- src/client/ui/handlers/ui.rs | 46 ++++++++++++++------------------ 5 files changed, 35 insertions(+), 31 deletions(-) diff --git a/src/client/ui/handlers/event.rs b/src/client/ui/handlers/event.rs index c66ea2b..b8cdf05 100644 --- a/src/client/ui/handlers/event.rs +++ b/src/client/ui/handlers/event.rs @@ -4,6 +4,7 @@ use crossterm::event::{Event, KeyCode, KeyModifiers}; use crate::client::terminal::AppTerminal; use crate::client::config::Config; use crate::proto::multieko2::PostAdresarRequest; +use super::form::FormState; pub struct EventHandler { pub command_mode: bool, diff --git a/src/client/ui/handlers/form.rs b/src/client/ui/handlers/form.rs index bf0b7d1..f636176 100644 --- a/src/client/ui/handlers/form.rs +++ b/src/client/ui/handlers/form.rs @@ -51,7 +51,15 @@ impl FormState { } } - pub fn render(&mut self, f: &mut Frame, area: Rect, theme: &Theme, is_edit_mode: bool, total_count: usize, current_position: usize) { + pub fn render( + &mut self, + f: &mut Frame, + area: Rect, + theme: &Theme, + is_edit_mode: bool, + total_count: u64, + current_position: u64, + ) { render_form( f, area, diff --git a/src/client/ui/handlers/render.rs b/src/client/ui/handlers/render.rs index 0061c3b..dba6f51 100644 --- a/src/client/ui/handlers/render.rs +++ b/src/client/ui/handlers/render.rs @@ -4,6 +4,7 @@ use crate::client::components1::{render_command_line, render_form, render_previe use crate::client::colors::Theme; use ratatui::layout::{Constraint, Direction, Layout, Rect}; use ratatui::Frame; +use super::form::FormState; pub fn render_ui( f: &mut Frame, 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 8fad0cc..9c3d361 100644 --- a/src/client/ui/handlers/ui.rs +++ b/src/client/ui/handlers/ui.rs @@ -1,18 +1,12 @@ // src/client/ui/handlers/ui.rs -use crossterm::event::{Event, KeyCode, KeyModifiers}; +use crossterm::event::Event; use crate::client::terminal::AppTerminal; -use crate::client::components1::{render_command_line, render_form, render_preview_card, render_status_line}; use crate::client::colors::Theme; use crate::client::config::Config; -use ratatui::layout::{Constraint, Direction, Layout}; -use std::env; -use crate::proto::multieko2::PostAdresarRequest; - -use super::form::FormState; -use super::event::EventHandler; +use ratatui::layout::Rect; +use super::{FormState, EventHandler, AppState}; use super::render::render_ui; -use super::state::AppState; pub async fn run_ui() -> Result<(), Box> { let config = Config::load()?; @@ -25,13 +19,13 @@ 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); - app_state.update_current_position(total_count + 1); + app_state.update_total_count(total_count.try_into().unwrap()); + app_state.update_current_position((total_count + 1).try_into().unwrap()); loop { // Fetch fresh total count on each iteration let total_count = app_terminal.get_adresar_count().await?; - app_state.update_total_count(total_count); + app_state.update_total_count(total_count.try_into().unwrap()); app_terminal.draw(|f| { render_ui( @@ -48,20 +42,20 @@ pub async fn run_ui() -> Result<(), Box> { ); })?; - if let Some(event) = app_terminal.read_event()? { - let (should_exit, message) = event_handler.handle_event( - event, - &config, - &mut app_terminal, - &mut form_state, - &mut app_state.is_saved, - app_state.total_count, - &mut app_state.current_position, - ).await?; - event_handler.command_message = message; - if should_exit { - return Ok(()); - } + let event = app_terminal.read_event()?; + let (should_exit, message) = event_handler.handle_event( + event, + &config, + &mut app_terminal, + &mut form_state, + &mut app_state.is_saved, + app_state.total_count, + &mut app_state.current_position, + ).await?; + + event_handler.command_message = message; + if should_exit { + return Ok(()); } } }