buttons are now added in the admin panel
This commit is contained in:
@@ -216,10 +216,27 @@ pub fn render_admin_panel_admin(
|
||||
].as_ref())
|
||||
.split(buttons_area);
|
||||
|
||||
let btn_style = Style::default().fg(theme.secondary); // Style for button text
|
||||
let btn1 = Paragraph::new("Add Logic").style(btn_style).alignment(Alignment::Center);
|
||||
let btn2 = Paragraph::new("Add Table").style(btn_style).alignment(Alignment::Center);
|
||||
let btn3 = Paragraph::new("Change Table").style(btn_style).alignment(Alignment::Center);
|
||||
let btn_base_style = Style::default().fg(theme.secondary);
|
||||
|
||||
// Define the helper closure to get style based on focus
|
||||
let get_btn_style = |button_focus: AdminFocus| {
|
||||
if admin_state.current_focus == button_focus {
|
||||
// Apply highlight style if this button is focused
|
||||
btn_base_style.add_modifier(ratatui::style::Modifier::REVERSED)
|
||||
} else {
|
||||
btn_base_style // Use base style otherwise
|
||||
}
|
||||
};
|
||||
let btn1 = Paragraph::new("Add Logic")
|
||||
.style(get_btn_style(AdminFocus::Button1))
|
||||
.alignment(Alignment::Center);
|
||||
let btn2 = Paragraph::new("Add Table")
|
||||
.style(get_btn_style(AdminFocus::Button2))
|
||||
.alignment(Alignment::Center);
|
||||
let btn3 = Paragraph::new("Change Table")
|
||||
.style(get_btn_style(AdminFocus::Button3))
|
||||
.alignment(Alignment::Center);
|
||||
|
||||
f.render_widget(btn1, button_chunks[0]);
|
||||
f.render_widget(btn2, button_chunks[1]);
|
||||
f.render_widget(btn3, button_chunks[2]);
|
||||
|
||||
@@ -43,6 +43,7 @@ pub fn handle_admin_navigation(
|
||||
}
|
||||
}
|
||||
}
|
||||
AdminFocus::Button1 | AdminFocus::Button2 | AdminFocus::Button3 => {}
|
||||
}
|
||||
true // Event handled
|
||||
}
|
||||
@@ -66,6 +67,7 @@ pub fn handle_admin_navigation(
|
||||
}
|
||||
}
|
||||
}
|
||||
AdminFocus::Button1 | AdminFocus::Button2 | AdminFocus::Button3 => {}
|
||||
}
|
||||
true // Event handled
|
||||
}
|
||||
@@ -73,13 +75,21 @@ 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();
|
||||
let is_next = action == Some("next_option"); // Check if 'l' or 'h'
|
||||
|
||||
admin_state.current_focus = match old_focus {
|
||||
AdminFocus::Profiles => if is_next { AdminFocus::Tables } else { AdminFocus::Button3 }, // P -> T (l) or P -> B3 (h)
|
||||
AdminFocus::Tables => if is_next { AdminFocus::Button1 } else { AdminFocus::Profiles }, // T -> B1 (l) or T -> P (h)
|
||||
AdminFocus::Button1 => if is_next { AdminFocus::Button2 } else { AdminFocus::Tables }, // B1 -> B2 (l) or B1 -> T (h)
|
||||
AdminFocus::Button2 => if is_next { AdminFocus::Button3 } else { AdminFocus::Button1 }, // B2 -> B3 (l) or B2 -> B1 (h)
|
||||
AdminFocus::Button3 => if is_next { AdminFocus::Profiles } else { AdminFocus::Button2 }, // B3 -> P (l) or B3 -> B2 (h)
|
||||
};
|
||||
|
||||
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
|
||||
// Auto-select first item only when moving from Profiles to Tables via 'l'
|
||||
if old_focus == AdminFocus::Profiles && new_focus == AdminFocus::Tables && is_next {
|
||||
if let Some(profile_idx) = admin_state.profile_list_state.selected() {
|
||||
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));
|
||||
@@ -93,6 +103,16 @@ pub fn handle_admin_navigation(
|
||||
admin_state.table_list_state.select(None);
|
||||
}
|
||||
}
|
||||
// Clear table nav selection if moving away from Tables
|
||||
if old_focus == AdminFocus::Tables && new_focus != AdminFocus::Tables {
|
||||
admin_state.table_list_state.select(None);
|
||||
}
|
||||
// Clear profile nav selection if moving away from Profiles
|
||||
if old_focus == AdminFocus::Profiles && new_focus != AdminFocus::Profiles {
|
||||
// Maybe keep profile nav highlight? Let's try clearing it.
|
||||
// admin_state.profile_list_state.select(None); // Optional: clear profile nav highlight
|
||||
}
|
||||
|
||||
true // Event handled
|
||||
}
|
||||
|
||||
@@ -104,8 +124,8 @@ pub fn handle_admin_navigation(
|
||||
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
|
||||
// Move focus to Tables (like pressing 'l')
|
||||
admin_state.current_focus = AdminFocus::Tables;
|
||||
|
||||
// Select the first table for navigation highlight
|
||||
admin_state.table_list_state.select(None); // Clear table nav first
|
||||
@@ -132,6 +152,18 @@ pub fn handle_admin_navigation(
|
||||
}
|
||||
// We don't change focus here for now.
|
||||
}
|
||||
AdminFocus::Button1 => {
|
||||
*command_message = "Action: Add Logic (Not Implemented)".to_string();
|
||||
// TODO: Trigger action for Button 1
|
||||
}
|
||||
AdminFocus::Button2 => {
|
||||
*command_message = "Action: Add Table (Not Implemented)".to_string();
|
||||
// TODO: Trigger action for Button 2
|
||||
}
|
||||
AdminFocus::Button3 => {
|
||||
*command_message = "Action: Change Table (Not Implemented)".to_string();
|
||||
// TODO: Trigger action for Button 3
|
||||
}
|
||||
}
|
||||
true // Event handled
|
||||
}
|
||||
@@ -146,4 +178,3 @@ pub fn handle_admin_navigation(
|
||||
_ => false, // Event not handled by admin navigation
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,9 @@ pub enum AdminFocus {
|
||||
#[default] // Default focus is on the profiles list
|
||||
Profiles,
|
||||
Tables,
|
||||
Button1,
|
||||
Button2,
|
||||
Button3,
|
||||
}
|
||||
|
||||
#[derive(Default, Clone, Debug)]
|
||||
@@ -169,14 +172,5 @@ impl AdminState {
|
||||
};
|
||||
self.select_table(Some(i));
|
||||
}
|
||||
|
||||
/// Toggles focus between the profile list and the table list.
|
||||
pub fn toggle_focus(&mut self) {
|
||||
self.current_focus = match self.current_focus {
|
||||
AdminFocus::Profiles => AdminFocus::Tables,
|
||||
AdminFocus::Tables => AdminFocus::Profiles,
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user