working selection in the admin panel for the admin perfectly well
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
// src/state/pages/admin.rs
|
||||
|
||||
use ratatui::widgets::ListState;
|
||||
use std::collections::HashSet;
|
||||
|
||||
// Define the focus states for the admin panel panes
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
|
||||
@@ -14,7 +15,8 @@ pub enum AdminFocus {
|
||||
pub struct AdminState {
|
||||
pub profiles: Vec<String>,
|
||||
pub profile_list_state: ListState, // State for the profiles list
|
||||
pub table_list_state: ListState, // State for the tables list
|
||||
pub table_list_state: ListState, // State for the tables list navigation/highlight
|
||||
pub selected_table_indices: HashSet<usize>, // Indices of tables marked with [*]
|
||||
pub current_focus: AdminFocus, // Tracks which pane is focused
|
||||
}
|
||||
|
||||
@@ -85,6 +87,7 @@ impl AdminState {
|
||||
pub fn select_profile(&mut self, index: Option<usize>) {
|
||||
self.profile_list_state.select(index);
|
||||
self.table_list_state.select(None); // Reset table selection
|
||||
self.selected_table_indices.clear();
|
||||
}
|
||||
|
||||
/// Selects a table by index.
|
||||
@@ -175,5 +178,17 @@ impl AdminState {
|
||||
AdminFocus::Tables => AdminFocus::Profiles,
|
||||
};
|
||||
}
|
||||
|
||||
/// Toggles the selection state of the table at the given index.
|
||||
pub fn toggle_table_selection(&mut self, index: usize) {
|
||||
if !self.selected_table_indices.remove(&index) {
|
||||
// If remove returned false, it wasn't present, so insert it.
|
||||
self.selected_table_indices.insert(index);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_table_selected(&self, index: usize) -> bool {
|
||||
self.selected_table_indices.contains(&index)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user