working admin panel, needs to do buttons for navigation next
This commit is contained in:
@@ -26,15 +26,15 @@ pub fn handle_admin_navigation(
|
||||
match current_focus {
|
||||
AdminFocus::Profiles => {
|
||||
if profile_count > 0 {
|
||||
// Updates navigation state, resets table state
|
||||
admin_state.previous_profile(profile_count);
|
||||
// Reset table selection when profile changes
|
||||
admin_state.table_list_state.select(None);
|
||||
*command_message = "Navigated profiles".to_string();
|
||||
}
|
||||
}
|
||||
AdminFocus::Tables => {
|
||||
if let Some(selected_profile_index) = admin_state.profile_list_state.selected() {
|
||||
if let Some(profile) = app_state.profile_tree.profiles.get(selected_profile_index) {
|
||||
// Updates table navigation state
|
||||
if let Some(nav_profile_idx) = admin_state.profile_list_state.selected() {
|
||||
if let Some(profile) = app_state.profile_tree.profiles.get(nav_profile_idx) {
|
||||
let table_count = profile.tables.len();
|
||||
if table_count > 0 {
|
||||
admin_state.previous_table(table_count);
|
||||
@@ -50,15 +50,14 @@ pub fn handle_admin_navigation(
|
||||
match current_focus {
|
||||
AdminFocus::Profiles => {
|
||||
if profile_count > 0 {
|
||||
// Updates navigation state, resets table state
|
||||
admin_state.next_profile(profile_count);
|
||||
// Reset table selection when profile changes
|
||||
admin_state.table_list_state.select(None);
|
||||
*command_message = "Navigated profiles".to_string();
|
||||
}
|
||||
}
|
||||
AdminFocus::Tables => {
|
||||
if let Some(selected_profile_index) = admin_state.profile_list_state.selected() {
|
||||
if let Some(profile) = app_state.profile_tree.profiles.get(selected_profile_index) {
|
||||
if let Some(nav_profile_idx) = admin_state.profile_list_state.selected() {
|
||||
if let Some(profile) = app_state.profile_tree.profiles.get(nav_profile_idx) {
|
||||
let table_count = profile.tables.len();
|
||||
if table_count > 0 {
|
||||
admin_state.next_table(table_count);
|
||||
@@ -73,8 +72,27 @@ pub fn handle_admin_navigation(
|
||||
|
||||
// --- Horizontal Navigation (Focus Change) ---
|
||||
Some("next_option") | Some("previous_option") => {
|
||||
let old_focus = admin_state.current_focus;
|
||||
admin_state.toggle_focus();
|
||||
*command_message = format!("Focus set to {:?}", admin_state.current_focus);
|
||||
let new_focus = admin_state.current_focus;
|
||||
*command_message = format!("Focus set to {:?}", new_focus);
|
||||
|
||||
// If focus moved TO Tables, select the first item for navigation
|
||||
if old_focus == AdminFocus::Profiles && new_focus == AdminFocus::Tables {
|
||||
if let Some(profile_idx) = admin_state.profile_list_state.selected() { // Use nav state
|
||||
if let Some(profile) = app_state.profile_tree.profiles.get(profile_idx) {
|
||||
if !profile.tables.is_empty() {
|
||||
admin_state.table_list_state.select(Some(0));
|
||||
} else {
|
||||
admin_state.table_list_state.select(None);
|
||||
}
|
||||
} else {
|
||||
admin_state.table_list_state.select(None);
|
||||
}
|
||||
} else {
|
||||
admin_state.table_list_state.select(None);
|
||||
}
|
||||
}
|
||||
true // Event handled
|
||||
}
|
||||
|
||||
@@ -82,29 +100,36 @@ pub fn handle_admin_navigation(
|
||||
Some("select") => {
|
||||
match current_focus {
|
||||
AdminFocus::Profiles => {
|
||||
// If a profile is selected, move focus to tables
|
||||
if admin_state.profile_list_state.selected().is_some() {
|
||||
admin_state.toggle_focus(); // Move focus to Tables
|
||||
// Optionally select the first table if available
|
||||
if let Some(selected_profile_index) = admin_state.profile_list_state.selected() {
|
||||
if let Some(profile) = app_state.profile_tree.profiles.get(selected_profile_index) {
|
||||
if !profile.tables.is_empty() {
|
||||
admin_state.table_list_state.select(Some(0));
|
||||
}
|
||||
}
|
||||
}
|
||||
*command_message = "Selected profile, focus on Tables".to_string();
|
||||
// Set the persistent selection to the currently navigated item
|
||||
if let Some(nav_idx) = admin_state.profile_list_state.selected() {
|
||||
admin_state.selected_profile_index = Some(nav_idx); // Set persistent selection
|
||||
|
||||
// Move focus to Tables
|
||||
admin_state.toggle_focus(); // Move focus
|
||||
|
||||
// Select the first table for navigation highlight
|
||||
admin_state.table_list_state.select(None); // Clear table nav first
|
||||
admin_state.selected_table_index = None; // Clear persistent table selection
|
||||
if let Some(profile) = app_state.profile_tree.profiles.get(nav_idx) {
|
||||
if !profile.tables.is_empty() {
|
||||
// Set table nav highlight
|
||||
admin_state.table_list_state.select(Some(0));
|
||||
}
|
||||
}
|
||||
|
||||
*command_message = format!("Selected profile idx {}, focus on Tables", nav_idx);
|
||||
} else {
|
||||
*command_message = "No profile selected".to_string();
|
||||
}
|
||||
}
|
||||
AdminFocus::Tables => {
|
||||
if let Some(idx) = admin_state.get_selected_table_index() {
|
||||
admin_state.toggle_table_selection(idx);
|
||||
*command_message = format!("Toggled selection for table index {}", idx);
|
||||
} else {
|
||||
// Set the persistent selection to the currently navigated item
|
||||
if let Some(nav_idx) = admin_state.table_list_state.selected() {
|
||||
admin_state.selected_table_index = Some(nav_idx); // Set persistent selection
|
||||
*command_message = format!("Selected table index {}", nav_idx);
|
||||
} else {
|
||||
*command_message = "No table highlighted".to_string();
|
||||
}
|
||||
}
|
||||
// We don't change focus here for now.
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user