code cleanup

This commit is contained in:
filipriec
2025-05-31 23:02:09 +02:00
parent ea88c2686d
commit 6e2fc5349b
5 changed files with 316 additions and 214 deletions

View File

@@ -1,9 +1,9 @@
// src/ui/handlers/render.rs
// client/src/ui/handlers/render.rs
use crate::components::{
render_background,
render_buffer_list,
render_command_line, // For the normal command line
render_command_line,
render_status_line,
intro::intro::render_intro,
handlers::sidebar::{self, calculate_sidebar_layout},
@@ -11,13 +11,11 @@ use crate::components::{
admin::render_add_table,
admin::add_logic::render_add_logic,
auth::{login::render_login, register::render_register},
common::find_file_palette, // Add this import
common::find_file_palette,
};
use crate::config::colors::themes::Theme;
use ratatui::{
// layout::{Constraint, Direction, Layout, Rect}, // Rect might be unused if all areas are handled
layout::{Constraint, Direction, Layout}, // Style might be unused if all styling is in components
// style::Style, // Style might be unused
layout::{Constraint, Direction, Layout},
Frame,
};
use crate::state::pages::canvas_state::CanvasState;
@@ -48,7 +46,7 @@ pub fn render_ui(
event_handler_command_input: &str,
event_handler_command_mode_active: bool,
event_handler_command_message: &str,
navigation_state: &NavigationState, // This is the correct reference
navigation_state: &NavigationState,
total_count: u64,
current_position: u64,
current_dir: &str,
@@ -59,26 +57,24 @@ pub fn render_ui(
const PALETTE_OPTIONS_HEIGHT_FOR_LAYOUT: u16 = 15;
let mut bottom_area_constraints: Vec<Constraint> = vec![Constraint::Length(1)]; // For status_line
let mut bottom_area_constraints: Vec<Constraint> = vec![Constraint::Length(1)];
let command_palette_area_height = if navigation_state.active {
1 + PALETTE_OPTIONS_HEIGHT_FOR_LAYOUT // Input line + fixed height for options
1 + PALETTE_OPTIONS_HEIGHT_FOR_LAYOUT
} else if event_handler_command_mode_active {
1 // Normal command line
1
} else {
0 // Neither is active
};
if command_palette_area_height > 0 {
// This constraint is for the command_render_area (palette or command line)
bottom_area_constraints.push(Constraint::Length(command_palette_area_height));
}
let mut main_layout_constraints = vec![Constraint::Min(1)]; // Main content area
let mut main_layout_constraints = vec![Constraint::Min(1)];
if app_state.ui.show_buffer_list {
main_layout_constraints.insert(0, Constraint::Length(1)); // Buffer list at the top
main_layout_constraints.insert(0, Constraint::Length(1));
}
// bottom_area_constraints already contains status_line and potentially command_palette_area
main_layout_constraints.extend(bottom_area_constraints);
@@ -103,12 +99,9 @@ pub fn render_ui(
chunk_idx += 1;
let command_render_area = if command_palette_area_height > 0 {
// Check if there's a chunk available for command_render_area
if root_chunks.len() > chunk_idx {
Some(root_chunks[chunk_idx])
} else {
// This case should ideally not happen if constraints are set up correctly
// but as a fallback, don't try to render if no area.
None
}
} else {
@@ -116,13 +109,12 @@ pub fn render_ui(
};
// --- Render main content views ---
if app_state.ui.show_intro {
render_intro(f, intro_state, main_content_area, theme);
} else if app_state.ui.show_register {
render_register(
f, main_content_area, theme, register_state, app_state,
register_state.current_field() < 4, // Assuming 4 fields before buttons
register_state.current_field() < 4,
highlight_state,
);
} else if app_state.ui.show_add_table {
@@ -139,7 +131,7 @@ pub fn render_ui(
} else if app_state.ui.show_login {
render_login(
f, main_content_area, theme, login_state, app_state,
login_state.current_field() < 2, // Assuming 2 fields before buttons
login_state.current_field() < 2,
highlight_state,
);
} else if app_state.ui.show_admin {
@@ -157,15 +149,14 @@ pub fn render_ui(
);
}
let available_width = form_actual_area.width;
// Center the form if space allows, otherwise use available width
let form_render_area = if available_width >= 80 {
Layout::default().direction(Direction::Horizontal)
.constraints([Constraint::Min(0), Constraint::Length(80), Constraint::Min(0)])
.split(form_actual_area)[1] // Use form_actual_area here
.split(form_actual_area)[1]
} else {
Layout::default().direction(Direction::Horizontal)
.constraints([Constraint::Min(0), Constraint::Length(available_width), Constraint::Min(0)])
.split(form_actual_area)[1] // Use form_actual_area here
.split(form_actual_area)[1]
};
let fields_vec: Vec<&str> = form_state.fields.iter().map(AsRef::as_ref).collect();
let values_vec: Vec<&String> = form_state.values.iter().collect();
@@ -175,16 +166,13 @@ pub fn render_ui(
total_count, current_position,
);
}
// --- End main content views ---
if let Some(area) = buffer_list_area {
// No need to check app_state.ui.show_buffer_list again, area is Some only if true
render_buffer_list(f, area, theme, buffer_state, app_state);
}
render_status_line(f, status_line_area, current_dir, theme, is_event_handler_edit_mode, current_fps);
// Render command line or find_file_palette
if let Some(palette_or_command_area) = command_render_area { // Use the calculated area
if navigation_state.active {
find_file_palette::render_find_file_palette(