not working, working on redesigning ui.rs
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<dyn std::error::Error>> {
|
||||
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
|
||||
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<dyn std::error::Error>> {
|
||||
);
|
||||
})?;
|
||||
|
||||
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(());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user