going directly into adminstate from appstate for the admin page. DESTROYED

This commit is contained in:
filipriec
2025-04-14 11:24:56 +02:00
parent 1927d1fa4d
commit 2d724876eb
10 changed files with 100 additions and 33 deletions

View File

@@ -27,11 +27,6 @@ pub struct UiState {
pub dialog: DialogState,
}
pub struct GeneralState {
pub selected_item: usize,
pub current_option: usize,
}
pub struct AppState {
// Core editor state
pub current_dir: String,
@@ -43,7 +38,6 @@ pub struct AppState {
// UI preferences
pub ui: UiState,
pub general: GeneralState,
}
impl AppState {
@@ -59,10 +53,6 @@ impl AppState {
selected_profile: None,
current_mode: AppMode::General,
ui: UiState::default(),
general: GeneralState {
selected_item: 0,
current_option: 0,
},
})
}

View File

@@ -2,4 +2,5 @@
pub mod form;
pub mod auth;
pub mod admin;
pub mod canvas_state;

View File

@@ -0,0 +1,38 @@
// src/state/pages/admin.rs
use ratatui::widgets::ListState;
#[derive(Default, Clone, Debug)]
pub struct AdminState {
pub profiles: Vec<String>,
pub list_state: ListState,
}
impl AdminState {
/// Gets the index of the currently selected item.
pub fn get_selected_index(&self) -> Option<usize> {
self.list_state.selected()
}
/// Gets the name of the currently selected profile.
pub fn get_selected_profile_name(&self) -> Option<&String> {
self.list_state.selected().and_then(|i| self.profiles.get(i))
}
/// Populates the profile list and updates/resets the selection.
pub fn set_profiles(&mut self, new_profiles: Vec<String>) {
let current_selection_index = self.list_state.selected();
self.profiles = new_profiles;
if self.profiles.is_empty() {
self.list_state.select(None);
} else {
let new_selection = match current_selection_index {
Some(index) => Some(index.min(self.profiles.len() - 1)),
None => Some(0),
};
self.list_state.select(new_selection);
}
}
}