separate page

This commit is contained in:
filipriec
2025-08-31 21:25:43 +02:00
parent 4e041f36ce
commit 5b42da8290
4 changed files with 76 additions and 48 deletions

View File

@@ -385,8 +385,8 @@ impl EventHandler {
key_event,
config,
app_state,
admin_state,
buffer_state,
router,
&mut self.command_message,
)? {
return Ok(EventOutcome::Ok(self.command_message.clone()));

View File

@@ -4,9 +4,9 @@ use crossterm::event::KeyEvent;
use crate::buffer::state::BufferState;
use crate::config::binds::config::Config;
use crate::pages::admin::AdminState;
use crate::pages::admin::main::logic::handle_admin_navigation;
use crate::state::app::state::AppState;
use crate::pages::routing::{Router, Page};
/// Handle all Admin page-specific key events (movement + actions).
/// Returns true if the key was handled (so the caller should stop propagation).
@@ -14,10 +14,11 @@ pub fn handle_admin_event(
key_event: KeyEvent,
config: &Config,
app_state: &mut AppState,
admin_state: &mut AdminState,
buffer_state: &mut BufferState,
router: &mut Router,
command_message: &mut String,
) -> Result<bool> {
if let Page::Admin(admin_state) = &mut router.current {
// 1) Map general action to MovementAction (same mapping used in event.rs)
let movement_action = if let Some(act) =
config.get_general_action(key_event.code, key_event.modifiers)
@@ -49,12 +50,16 @@ pub fn handle_admin_event(
key_event,
config,
app_state,
admin_state,
buffer_state,
router,
command_message,
) {
return Ok(true);
}
// If we reached here, nothing was handled
return Ok(false);
}
Ok(false)
}

View File

@@ -5,7 +5,8 @@ use crate::config::binds::config::Config;
use crate::buffer::state::{BufferState, AppView};
use crate::pages::admin_panel::add_table::state::{AddTableState, LinkDefinition};
use ratatui::widgets::ListState;
use crate::pages::admin_panel::add_logic::state::{AddLogicState, AddLogicFocus};
use crate::pages::admin_panel::add_logic::state::{AddLogicState, AddLogicFocus, AddLogicFormState};
use crate::pages::routing::{Page, Router};
// Helper functions list_select_next and list_select_previous remain the same
fn list_select_next(list_state: &mut ListState, item_count: usize) {
@@ -36,11 +37,15 @@ pub fn handle_admin_navigation(
key: crossterm::event::KeyEvent,
config: &Config,
app_state: &mut AppState,
admin_state: &mut AdminState,
buffer_state: &mut BufferState,
router: &mut Router,
command_message: &mut String,
) -> bool {
let action = config.get_general_action(key.code, key.modifiers).map(String::from);
let Page::Admin(admin_state) = &mut router.current else {
return false;
};
let current_focus = admin_state.current_focus;
let profile_count = app_state.profile_tree.profiles.len();
let mut handled = false;
@@ -230,20 +235,20 @@ pub fn handle_admin_navigation(
if let Some(profile) = app_state.profile_tree.profiles.get(p_idx) {
if let Some(t_idx) = admin_state.selected_table_index {
if let Some(table) = profile.tables.get(t_idx) {
// Both profile and table are selected, proceed
admin_state.add_logic_state = AddLogicState {
profile_name: profile.name.clone(),
selected_table_name: Some(table.name.clone()),
selected_table_id: Some(table.id), // If you have table IDs
editor_keybinding_mode: config.editor.keybinding_mode.clone(),
current_focus: AddLogicFocus::default(),
..AddLogicState::default()
};
// Create AddLogic page with selected profile & table
let add_logic_form = AddLogicFormState::new_with_table(
&config.editor,
profile.name.clone(),
Some(table.id),
table.name.clone(),
);
// Route to AddLogic
router.current = Page::AddLogic(add_logic_form);
// Store table info for later fetching
app_state.pending_table_structure_fetch = Some((
profile.name.clone(),
table.name.clone()
table.name.clone(),
));
buffer_state.update_history(AppView::AddLogic);

View File

@@ -358,6 +358,24 @@ impl AddLogicFormState {
}
}
pub fn new_with_table(
editor_config: &EditorConfig,
profile_name: String,
table_id: Option<i64>,
table_name: String,
) -> Self {
let mut state = AddLogicState::new(editor_config);
state.profile_name = profile_name;
state.selected_table_id = table_id;
state.selected_table_name = Some(table_name);
let editor = FormEditor::new(state.clone());
Self {
state,
editor,
focus_outside_canvas: false,
}
}
pub fn from_state(state: AddLogicState) -> Self {
let editor = FormEditor::new(state.clone());
Self {