not working, working on redesigning ui.rs

This commit is contained in:
filipriec
2025-02-18 23:09:29 +01:00
parent 98baeabce2
commit 054d647d83
5 changed files with 35 additions and 31 deletions

View File

@@ -4,6 +4,7 @@ use crossterm::event::{Event, KeyCode, KeyModifiers};
use crate::client::terminal::AppTerminal; use crate::client::terminal::AppTerminal;
use crate::client::config::Config; use crate::client::config::Config;
use crate::proto::multieko2::PostAdresarRequest; use crate::proto::multieko2::PostAdresarRequest;
use super::form::FormState;
pub struct EventHandler { pub struct EventHandler {
pub command_mode: bool, pub command_mode: bool,

View File

@@ -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( render_form(
f, f,
area, area,

View File

@@ -4,6 +4,7 @@ use crate::client::components1::{render_command_line, render_form, render_previe
use crate::client::colors::Theme; use crate::client::colors::Theme;
use ratatui::layout::{Constraint, Direction, Layout, Rect}; use ratatui::layout::{Constraint, Direction, Layout, Rect};
use ratatui::Frame; use ratatui::Frame;
use super::form::FormState;
pub fn render_ui( pub fn render_ui(
f: &mut Frame, f: &mut Frame,

View File

@@ -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: usize, pub total_count: u64,
pub current_position: usize, pub current_position: u64,
} }
impl AppState { 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; 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; self.current_position = current_position;
} }
} }

View File

@@ -1,18 +1,12 @@
// src/client/ui/handlers/ui.rs // src/client/ui/handlers/ui.rs
use crossterm::event::{Event, KeyCode, KeyModifiers}; use crossterm::event::Event;
use crate::client::terminal::AppTerminal; 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::colors::Theme;
use crate::client::config::Config; use crate::client::config::Config;
use ratatui::layout::{Constraint, Direction, Layout}; use ratatui::layout::Rect;
use std::env; use super::{FormState, EventHandler, AppState};
use crate::proto::multieko2::PostAdresarRequest;
use super::form::FormState;
use super::event::EventHandler;
use super::render::render_ui; use super::render::render_ui;
use super::state::AppState;
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()?;
@@ -25,13 +19,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?;
app_state.update_total_count(total_count); app_state.update_total_count(total_count.try_into().unwrap());
app_state.update_current_position(total_count + 1); app_state.update_current_position((total_count + 1).try_into().unwrap());
loop { loop {
// Fetch fresh total count on each iteration // 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); app_state.update_total_count(total_count.try_into().unwrap());
app_terminal.draw(|f| { app_terminal.draw(|f| {
render_ui( render_ui(
@@ -48,7 +42,7 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
); );
})?; })?;
if let Some(event) = app_terminal.read_event()? { let event = app_terminal.read_event()?;
let (should_exit, message) = event_handler.handle_event( let (should_exit, message) = event_handler.handle_event(
event, event,
&config, &config,
@@ -58,10 +52,10 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
app_state.total_count, app_state.total_count,
&mut app_state.current_position, &mut app_state.current_position,
).await?; ).await?;
event_handler.command_message = message; event_handler.command_message = message;
if should_exit { if should_exit {
return Ok(()); return Ok(());
} }
} }
}
} }