router implementation

This commit is contained in:
Priec
2025-08-22 22:19:59 +02:00
parent 6833ac5fad
commit 957f5bf9f0
9 changed files with 225 additions and 180 deletions

View File

@@ -28,16 +28,11 @@ use ratatui::{
layout::{Constraint, Direction, Layout},
Frame,
};
use crate::pages::routing::{Router, Page};
#[allow(clippy::too_many_arguments)]
pub fn render_ui(
f: &mut Frame,
form_state: &mut FormState,
auth_state: &mut AuthState,
login_state: &LoginState,
register_state: &RegisterState,
intro_state: &IntroState,
admin_state: &mut AdminState,
router: &mut Router,
buffer_state: &BufferState,
theme: &Theme,
is_event_handler_edit_mode: bool,
@@ -78,101 +73,97 @@ pub fn render_ui(
let main_content_area = root_chunks[chunk_idx];
chunk_idx += 1;
if app_state.ui.show_intro {
render_intro(f, intro_state, main_content_area, theme);
} else if app_state.ui.show_register {
render_register(
// ✅ Instead of checking app_state.ui.show_*, just match router.current
match &mut router.current {
Page::Intro(state) => render_intro(f, state, main_content_area, theme),
Page::Login(state) => render_login(
f,
main_content_area,
theme,
register_state,
state,
app_state,
register_state.current_field() < 4, // Now using CanvasState trait method
);
} else if app_state.ui.show_add_table {
render_add_table(
state.current_field() < 2,
),
Page::Register(state) => render_register(
f,
main_content_area,
theme,
state,
app_state,
&mut admin_state.add_table_state,
is_event_handler_edit_mode,
);
} else if app_state.ui.show_add_logic {
render_add_logic(
f,
main_content_area,
theme,
app_state,
&mut admin_state.add_logic_state,
is_event_handler_edit_mode,
);
} else if app_state.ui.show_login {
render_login(
f,
main_content_area,
theme,
login_state,
app_state,
login_state.current_field() < 2, // Now using CanvasState trait method
);
} else if app_state.ui.show_admin {
crate::components::admin::admin_panel::render_admin_panel(
state.current_field() < 4,
),
Page::Admin(state) => crate::components::admin::admin_panel::render_admin_panel(
f,
app_state,
auth_state,
admin_state,
&mut AuthState::default(), // TODO: later move AuthState into Router
state,
main_content_area,
theme,
&app_state.profile_tree,
&app_state.selected_profile,
);
} else if app_state.ui.show_form {
let (sidebar_area, form_actual_area) =
calculate_sidebar_layout(app_state.ui.show_sidebar, main_content_area);
if let Some(sidebar_rect) = sidebar_area {
render_sidebar(
),
Page::AddLogic(state) => render_add_logic(
f,
main_content_area,
theme,
app_state,
state,
is_event_handler_edit_mode,
),
Page::AddTable(state) => render_add_table(
f,
main_content_area,
theme,
app_state,
state,
is_event_handler_edit_mode,
),
Page::Form(state) => {
let (sidebar_area, form_actual_area) =
calculate_sidebar_layout(app_state.ui.show_sidebar, main_content_area);
if let Some(sidebar_rect) = sidebar_area {
render_sidebar(
f,
sidebar_rect,
theme,
&app_state.profile_tree,
&app_state.selected_profile,
);
}
let available_width = form_actual_area.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]
} else {
Layout::default()
.direction(Direction::Horizontal)
.constraints([
Constraint::Min(0),
Constraint::Length(available_width),
Constraint::Min(0),
])
.split(form_actual_area)[1]
};
render_form(
f,
sidebar_rect,
form_render_area,
app_state,
state,
app_state.current_view_table_name.as_deref().unwrap_or(""),
theme,
&app_state.profile_tree,
&app_state.selected_profile,
state.total_count,
state.current_position,
);
}
let available_width = form_actual_area.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]
} else {
Layout::default()
.direction(Direction::Horizontal)
.constraints([
Constraint::Min(0),
Constraint::Length(available_width),
Constraint::Min(0),
])
.split(form_actual_area)[1]
};
render_form(
f,
form_render_area,
app_state,
form_state,
app_state.current_view_table_name.as_deref().unwrap_or(""),
theme,
form_state.total_count,
form_state.current_position,
);
}
if let Some(area) = buffer_list_area {
render_buffer_list(f, area, theme, buffer_state, app_state);
}
// This block now correctly handles drawing popups over any view.
if app_state.ui.show_search_palette {
if let Some(search_state) = &app_state.search_state {
render_search_palette(f, f.area(), theme, search_state);