Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
990ec9317f | ||
|
|
718ceac17e | ||
|
|
d154ba6b89 | ||
|
|
f2a63476b3 | ||
|
|
adcd3b37fa | ||
|
|
71dabc1e37 |
@@ -1,118 +1,108 @@
|
||||
// src/components/admin/admin_panel.rs
|
||||
|
||||
use crate::config::colors::themes::Theme;
|
||||
use crate::state::pages::admin::AdminState; // Import the persistent state
|
||||
use common::proto::multieko2::table_definition::ProfileTreeResponse;
|
||||
use ratatui::{
|
||||
widgets::{Block, BorderType, Borders, List, ListItem, ListState, Paragraph},
|
||||
style::Style,
|
||||
text::{Line, Span, Text},
|
||||
layout::{Alignment, Constraint, Direction, Layout, Rect},
|
||||
style::Style, // Added Modifier
|
||||
text::{Line, Span, Text},
|
||||
widgets::{Block, BorderType, Borders, List, ListItem, Paragraph, Wrap},
|
||||
Frame,
|
||||
};
|
||||
use common::proto::multieko2::table_definition::ProfileTreeResponse;
|
||||
use crate::config::colors::themes::Theme;
|
||||
|
||||
pub struct AdminPanelState {
|
||||
pub list_state: ListState,
|
||||
pub profiles: Vec<String>,
|
||||
}
|
||||
// Renamed from AdminPanelState::render and made a standalone function
|
||||
pub fn render_admin_panel(
|
||||
f: &mut Frame,
|
||||
admin_state: &AdminState, // Accept the persistent state (immutable borrow is enough for rendering)
|
||||
area: Rect,
|
||||
theme: &Theme,
|
||||
profile_tree: &ProfileTreeResponse,
|
||||
selected_profile: &Option<String>, // The globally selected profile for the checkmark
|
||||
) {
|
||||
let block = Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.border_type(BorderType::Rounded)
|
||||
.border_style(Style::default().fg(theme.accent))
|
||||
.style(Style::default().bg(theme.bg));
|
||||
|
||||
impl AdminPanelState {
|
||||
pub fn new(profiles: Vec<String>) -> Self {
|
||||
let mut list_state = ListState::default();
|
||||
if !profiles.is_empty() {
|
||||
list_state.select(Some(0));
|
||||
}
|
||||
Self { list_state, profiles }
|
||||
}
|
||||
let inner_area = block.inner(area);
|
||||
f.render_widget(block, area);
|
||||
|
||||
pub fn next(&mut self) {
|
||||
let i = self.list_state.selected().map_or(0, |i|
|
||||
if i >= self.profiles.len() - 1 { 0 } else { i + 1 });
|
||||
self.list_state.select(Some(i));
|
||||
}
|
||||
let chunks = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.constraints([Constraint::Length(3), Constraint::Min(1)])
|
||||
.split(inner_area);
|
||||
|
||||
pub fn previous(&mut self) {
|
||||
let i = self.list_state.selected().map_or(0, |i|
|
||||
if i == 0 { self.profiles.len() - 1 } else { i - 1 });
|
||||
self.list_state.select(Some(i));
|
||||
}
|
||||
// Title
|
||||
let title = Line::from(Span::styled("Admin Panel", Style::default().fg(theme.highlight)));
|
||||
let title_widget = Paragraph::new(title).alignment(Alignment::Center);
|
||||
f.render_widget(title_widget, chunks[0]);
|
||||
|
||||
pub fn render(
|
||||
&mut self,
|
||||
f: &mut Frame,
|
||||
area: Rect,
|
||||
theme: &Theme,
|
||||
profile_tree: &ProfileTreeResponse,
|
||||
selected_profile: &Option<String>,
|
||||
) {
|
||||
let block = Block::default()
|
||||
.borders(Borders::ALL)
|
||||
.border_type(BorderType::Rounded)
|
||||
.border_style(Style::default().fg(theme.accent))
|
||||
.style(Style::default().bg(theme.bg));
|
||||
// Content
|
||||
let content_chunks = Layout::default()
|
||||
.direction(Direction::Horizontal)
|
||||
.constraints([Constraint::Percentage(30), Constraint::Percentage(70)])
|
||||
.split(chunks[1]);
|
||||
|
||||
let inner_area = block.inner(area);
|
||||
f.render_widget(block, area);
|
||||
|
||||
let chunks = Layout::default()
|
||||
.direction(Direction::Vertical)
|
||||
.constraints([Constraint::Length(3), Constraint::Min(1)])
|
||||
.split(inner_area);
|
||||
|
||||
// Title
|
||||
let title = Line::from(Span::styled("Admin Panel", Style::default().fg(theme.highlight)));
|
||||
let title_widget = Paragraph::new(title).alignment(Alignment::Center);
|
||||
f.render_widget(title_widget, chunks[0]);
|
||||
|
||||
// Content
|
||||
let content_chunks = Layout::default()
|
||||
.direction(Direction::Horizontal)
|
||||
.constraints([Constraint::Percentage(30), Constraint::Percentage(70)])
|
||||
.split(chunks[1]);
|
||||
|
||||
// Profile list
|
||||
let items: Vec<ListItem> = self.profiles.iter()
|
||||
.map(|p| ListItem::new(Line::from(vec![
|
||||
// Profile list - Use data from admin_state
|
||||
let items: Vec<ListItem> = admin_state
|
||||
.profiles // Use profiles from the persistent state
|
||||
.iter()
|
||||
.map(|p| {
|
||||
ListItem::new(Line::from(vec![
|
||||
Span::styled(
|
||||
// Check against the globally selected profile for the checkmark
|
||||
if Some(p) == selected_profile.as_ref() { "✓ " } else { " " },
|
||||
Style::default().fg(theme.accent)
|
||||
Style::default().fg(theme.accent),
|
||||
),
|
||||
Span::styled(p, Style::default().fg(theme.fg)),
|
||||
])))
|
||||
.collect();
|
||||
]))
|
||||
})
|
||||
.collect();
|
||||
|
||||
let list = List::new(items)
|
||||
.block(Block::default().title("Profiles"))
|
||||
.highlight_style(Style::default().bg(theme.highlight).fg(theme.bg));
|
||||
|
||||
f.render_stateful_widget(list, content_chunks[0], &mut self.list_state);
|
||||
let list = List::new(items)
|
||||
.block(Block::default().title("Profiles"))
|
||||
.highlight_style(Style::default().bg(theme.highlight).fg(theme.bg));
|
||||
|
||||
// Profile details
|
||||
if let Some(profile) = self.list_state.selected()
|
||||
.and_then(|i| profile_tree.profiles.get(i))
|
||||
{
|
||||
let mut text = Text::default();
|
||||
text.lines.push(Line::from(vec![
|
||||
Span::styled("Profile: ", Style::default().fg(theme.accent)),
|
||||
Span::styled(&profile.name, Style::default().fg(theme.highlight)),
|
||||
]));
|
||||
// Render statefully using a CLONE of the list_state from persistent AdminState
|
||||
// Cloning is necessary because render_stateful_widget needs `&mut ListState`
|
||||
// but we only have `&AdminState`. This is a common pattern in Ratatui.
|
||||
let mut list_state_clone = admin_state.list_state.clone();
|
||||
f.render_stateful_widget(list, content_chunks[0], &mut list_state_clone);
|
||||
|
||||
text.lines.push(Line::from(""));
|
||||
text.lines.push(Line::from(Span::styled("Tables:", Style::default().fg(theme.accent))));
|
||||
|
||||
for table in &profile.tables {
|
||||
let mut line = vec![Span::styled(format!("├─ {}", table.name), theme.fg)];
|
||||
if !table.depends_on.is_empty() {
|
||||
line.push(Span::styled(
|
||||
format!(" → {}", table.depends_on.join(", ")),
|
||||
Style::default().fg(theme.secondary)
|
||||
));
|
||||
}
|
||||
text.lines.push(Line::from(line));
|
||||
// Profile details - Use selection info from admin_state
|
||||
if let Some(profile) = admin_state
|
||||
.get_selected_index() // Use the method from persistent state
|
||||
.and_then(|i| profile_tree.profiles.get(i))
|
||||
{
|
||||
let mut text = Text::default();
|
||||
text.lines.push(Line::from(vec![
|
||||
Span::styled("Profile: ", Style::default().fg(theme.accent)),
|
||||
Span::styled(&profile.name, Style::default().fg(theme.highlight)),
|
||||
]));
|
||||
|
||||
text.lines.push(Line::from(""));
|
||||
text.lines.push(Line::from(Span::styled(
|
||||
"Tables:",
|
||||
Style::default().fg(theme.accent),
|
||||
)));
|
||||
|
||||
for table in &profile.tables {
|
||||
let mut line = vec![Span::styled(format!("├─ {}", table.name), theme.fg)];
|
||||
if !table.depends_on.is_empty() {
|
||||
line.push(Span::styled(
|
||||
format!(" → {}", table.depends_on.join(", ")),
|
||||
Style::default().fg(theme.secondary),
|
||||
));
|
||||
}
|
||||
|
||||
let details_widget = Paragraph::new(text)
|
||||
.block(Block::default().title("Details"));
|
||||
f.render_widget(details_widget, content_chunks[1]);
|
||||
text.lines.push(Line::from(line));
|
||||
}
|
||||
|
||||
let details_widget = Paragraph::new(text)
|
||||
.block(Block::default().title("Details"))
|
||||
.wrap(Wrap { trim: true }); // Add wrapping
|
||||
f.render_widget(details_widget, content_chunks[1]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ pub fn render_login(
|
||||
// Login Button
|
||||
let login_button_index = 0;
|
||||
let login_active = if app_state.ui.focus_outside_canvas {
|
||||
app_state.general.selected_item == login_button_index
|
||||
app_state.focused_button_index== login_button_index
|
||||
} else {
|
||||
false
|
||||
};
|
||||
@@ -104,7 +104,7 @@ pub fn render_login(
|
||||
// Return Button
|
||||
let return_button_index = 1; // Assuming Return is the second general element
|
||||
let return_active = if app_state.ui.focus_outside_canvas {
|
||||
app_state.general.selected_item == return_button_index
|
||||
app_state.focused_button_index== return_button_index
|
||||
} else {
|
||||
false // Not active if focus is in canvas or other modes
|
||||
};
|
||||
|
||||
@@ -11,7 +11,7 @@ use crate::{
|
||||
use ratatui::{
|
||||
layout::{Alignment, Constraint, Direction, Layout, Rect, Margin},
|
||||
style::{Style, Modifier, Color},
|
||||
widgets::{Block, BorderType, Borders, Paragraph, Wrap},
|
||||
widgets::{Block, BorderType, Borders, Paragraph},
|
||||
Frame,
|
||||
};
|
||||
|
||||
@@ -92,7 +92,7 @@ pub fn render_register(
|
||||
// Register Button
|
||||
let register_button_index = 0;
|
||||
let register_active = if app_state.ui.focus_outside_canvas {
|
||||
app_state.general.selected_item == register_button_index
|
||||
app_state.focused_button_index== register_button_index
|
||||
} else {
|
||||
false
|
||||
};
|
||||
@@ -119,7 +119,7 @@ pub fn render_register(
|
||||
// Return Button (logic remains similar)
|
||||
let return_button_index = 1;
|
||||
let return_active = if app_state.ui.focus_outside_canvas {
|
||||
app_state.general.selected_item == return_button_index
|
||||
app_state.focused_button_index== return_button_index
|
||||
} else {
|
||||
false
|
||||
};
|
||||
|
||||
@@ -9,8 +9,6 @@ use ratatui::{
|
||||
};
|
||||
use crate::config::colors::themes::Theme;
|
||||
use crate::state::pages::canvas_state::CanvasState;
|
||||
use crate::components::common::autocomplete;
|
||||
use crate::components::render_autocomplete_dropdown;
|
||||
|
||||
pub fn render_canvas(
|
||||
f: &mut Frame,
|
||||
|
||||
@@ -6,4 +6,3 @@ pub mod navigation;
|
||||
|
||||
pub use read_only::*;
|
||||
pub use edit::*;
|
||||
pub use navigation::*;
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
// src/functions/modes/navigation.rs
|
||||
|
||||
pub mod admin_nav;
|
||||
// pub mod admin_nav;
|
||||
|
||||
@@ -1,36 +1 @@
|
||||
// src/functions/modes/navigation/admin_nav.rs
|
||||
|
||||
use crate::state::app::state::AppState;
|
||||
use crate::state::pages::admin::AdminState;
|
||||
|
||||
/// Handles moving the selection up in the admin profile list.
|
||||
pub fn move_admin_list_up(app_state: &AppState, admin_state: &mut AdminState) {
|
||||
// Read profile count directly from app_state where the source data lives
|
||||
let profile_count = app_state.profile_tree.profiles.len();
|
||||
if profile_count == 0 {
|
||||
admin_state.list_state.select(None); // Ensure nothing selected if empty
|
||||
return;
|
||||
}
|
||||
|
||||
let current_index = admin_state.get_selected_index().unwrap_or(0);
|
||||
let new_index = if current_index == 0 {
|
||||
profile_count - 1 // Wrap to end
|
||||
} else {
|
||||
current_index.saturating_sub(1) // Move up
|
||||
};
|
||||
admin_state.list_state.select(Some(new_index));
|
||||
}
|
||||
|
||||
/// Handles moving the selection down in the admin profile list.
|
||||
pub fn move_admin_list_down(app_state: &AppState, admin_state: &mut AdminState) {
|
||||
// Read profile count directly from app_state
|
||||
let profile_count = app_state.profile_tree.profiles.len();
|
||||
if profile_count == 0 {
|
||||
admin_state.list_state.select(None); // Ensure nothing selected if empty
|
||||
return;
|
||||
}
|
||||
|
||||
let current_index = admin_state.get_selected_index().unwrap_or(0);
|
||||
let new_index = (current_index + 1) % profile_count; // Wrap around
|
||||
admin_state.list_state.select(Some(new_index));
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ pub async fn execute_action<S: CanvasState>(
|
||||
if current_field == last_field_index {
|
||||
// Already on the last field, move focus outside
|
||||
app_state.ui.focus_outside_canvas = true;
|
||||
app_state.general.selected_item = 0; // Focus first general item (e.g., Login button)
|
||||
app_state.focused_button_index= 0;
|
||||
key_sequence_tracker.reset();
|
||||
Ok("Focus moved below canvas".to_string())
|
||||
} else {
|
||||
|
||||
@@ -4,7 +4,6 @@ use crate::config::binds::config::Config;
|
||||
use crate::config::binds::key_sequences::KeySequenceTracker;
|
||||
use crate::services::grpc_client::GrpcClient;
|
||||
use crate::state::pages::{canvas_state::CanvasState, auth::RegisterState};
|
||||
use crate::state::pages::auth::AuthState;
|
||||
use crate::state::pages::auth::LoginState;
|
||||
use crate::state::pages::form::FormState;
|
||||
use crate::state::app::state::AppState;
|
||||
|
||||
@@ -7,7 +7,6 @@ use crate::state::app::state::AppState;
|
||||
use crate::state::pages::auth::AuthState;
|
||||
use crate::state::pages::auth::LoginState;
|
||||
use crate::state::pages::auth::RegisterState;
|
||||
use crate::services::auth::AuthClient;
|
||||
use crate::modes::handlers::event::EventOutcome;
|
||||
use crate::tui::functions::common::{login, register};
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ use crate::state::pages::admin::AdminState;
|
||||
use crate::state::pages::canvas_state::CanvasState;
|
||||
use crate::ui::handlers::context::UiContext;
|
||||
use crate::modes::handlers::event::EventOutcome;
|
||||
use crate::functions::modes::navigation::admin_nav;
|
||||
|
||||
pub async fn handle_navigation_event(
|
||||
key: KeyEvent,
|
||||
@@ -64,15 +63,14 @@ pub async fn handle_navigation_event(
|
||||
let (context, index) = if app_state.ui.show_intro {
|
||||
(UiContext::Intro, app_state.ui.intro_state.selected_option)
|
||||
} else if app_state.ui.show_login && app_state.ui.focus_outside_canvas {
|
||||
(UiContext::Login, app_state.general.selected_item)
|
||||
(UiContext::Login, app_state.focused_button_index)
|
||||
} else if app_state.ui.show_register && app_state.ui.focus_outside_canvas {
|
||||
(UiContext::Register, app_state.general.selected_item)
|
||||
(UiContext::Register, app_state.focused_button_index)
|
||||
} else if app_state.ui.show_admin {
|
||||
(UiContext::Admin, app_state.general.selected_item)
|
||||
(UiContext::Admin, admin_state.get_selected_index().unwrap_or(0))
|
||||
} else if app_state.ui.dialog.dialog_show {
|
||||
(UiContext::Dialog, app_state.ui.dialog.dialog_active_button_index)
|
||||
} else {
|
||||
// Handle cases where select is pressed but no button context applies
|
||||
return Ok(EventOutcome::Ok("Select (No Action)".to_string()));
|
||||
};
|
||||
return Ok(EventOutcome::ButtonSelected { context, index });
|
||||
@@ -85,7 +83,7 @@ pub async fn handle_navigation_event(
|
||||
|
||||
pub fn move_up(app_state: &mut AppState, login_state: &mut LoginState, register_state: &mut RegisterState, admin_state: &mut AdminState) {
|
||||
if app_state.ui.focus_outside_canvas && app_state.ui.show_login || app_state.ui.show_register{
|
||||
if app_state.general.selected_item == 0 {
|
||||
if app_state.focused_button_index == 0 {
|
||||
app_state.ui.focus_outside_canvas = false;
|
||||
if app_state.ui.show_login {
|
||||
let last_field_index = login_state.fields().len().saturating_sub(1);
|
||||
@@ -95,31 +93,25 @@ pub fn move_up(app_state: &mut AppState, login_state: &mut LoginState, register_
|
||||
register_state.set_current_field(last_field_index);
|
||||
}
|
||||
} else {
|
||||
app_state.general.selected_item = app_state.general.selected_item.saturating_sub(1);
|
||||
app_state.focused_button_index = app_state.focused_button_index.saturating_sub(1);
|
||||
}
|
||||
} else if app_state.ui.show_intro {
|
||||
app_state.ui.intro_state.previous_option();
|
||||
} else if app_state.ui.show_admin {
|
||||
admin_nav::move_admin_list_up(app_state, admin_state);
|
||||
admin_state.previous();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn move_down(app_state: &mut AppState, admin_state: &mut AdminState) {
|
||||
if app_state.ui.focus_outside_canvas && app_state.ui.show_login || app_state.ui.show_register {
|
||||
let num_general_elements = 2;
|
||||
if app_state.general.selected_item < num_general_elements - 1 {
|
||||
app_state.general.selected_item += 1;
|
||||
if app_state.focused_button_index < num_general_elements - 1 {
|
||||
app_state.focused_button_index += 1;
|
||||
}
|
||||
} else if app_state.ui.show_intro {
|
||||
app_state.ui.intro_state.next_option();
|
||||
} else if app_state.ui.show_admin {
|
||||
// Assuming profile_tree.profiles is the list we're navigating
|
||||
let profile_count = app_state.profile_tree.profiles.len();
|
||||
if profile_count == 0 {
|
||||
return;
|
||||
}
|
||||
|
||||
admin_nav::move_admin_list_down(app_state, admin_state);
|
||||
admin_state.next();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -129,7 +121,7 @@ pub fn next_option(app_state: &mut AppState) { // Remove option_count parameter
|
||||
} else {
|
||||
// Get option count from state instead of parameter
|
||||
let option_count = app_state.profile_tree.profiles.len();
|
||||
app_state.general.current_option = (app_state.general.current_option + 1) % option_count;
|
||||
app_state.focused_button_index = (app_state.focused_button_index + 1) % option_count;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,10 +130,10 @@ pub fn previous_option(app_state: &mut AppState) {
|
||||
app_state.ui.intro_state.previous_option();
|
||||
} else {
|
||||
let option_count = app_state.profile_tree.profiles.len();
|
||||
app_state.general.current_option = if app_state.general.current_option == 0 {
|
||||
option_count.saturating_sub(1) // Wrap to last option
|
||||
app_state.focused_button_index = if app_state.focused_button_index == 0 {
|
||||
option_count.saturating_sub(1)
|
||||
} else {
|
||||
app_state.general.current_option - 1
|
||||
app_state.focused_button_index - 1
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,7 +119,13 @@ impl EventHandler {
|
||||
let mut message = String::from("Selected"); // Default message
|
||||
match context {
|
||||
UiContext::Intro => {
|
||||
intro::handle_intro_selection(app_state, index); // Pass index
|
||||
intro::handle_intro_selection(app_state, index);
|
||||
if app_state.ui.show_admin {
|
||||
let profile_names = app_state.profile_tree.profiles.iter()
|
||||
.map(|p| p.name.clone())
|
||||
.collect();
|
||||
admin_state.set_profiles(profile_names);
|
||||
}
|
||||
message = format!("Intro Option {} selected", index);
|
||||
}
|
||||
UiContext::Login => {
|
||||
@@ -137,7 +143,7 @@ impl EventHandler {
|
||||
};
|
||||
}
|
||||
UiContext::Admin => {
|
||||
admin::handle_admin_selection(app_state);
|
||||
admin::handle_admin_selection(app_state, admin_state);
|
||||
|
||||
message = format!("Admin Option {} selected", index);
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ pub struct AppState {
|
||||
pub profile_tree: ProfileTreeResponse,
|
||||
pub selected_profile: Option<String>,
|
||||
pub current_mode: AppMode,
|
||||
pub focused_button_index: usize,
|
||||
|
||||
// UI preferences
|
||||
pub ui: UiState,
|
||||
@@ -52,6 +53,7 @@ impl AppState {
|
||||
profile_tree: ProfileTreeResponse::default(),
|
||||
selected_profile: None,
|
||||
current_mode: AppMode::General,
|
||||
focused_button_index: 0,
|
||||
ui: UiState::default(),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -34,5 +34,32 @@ impl AdminState {
|
||||
self.list_state.select(new_selection);
|
||||
}
|
||||
}
|
||||
|
||||
/// Selects the next profile in the list, wrapping around.
|
||||
pub fn next(&mut self) {
|
||||
if self.profiles.is_empty() {
|
||||
self.list_state.select(None);
|
||||
return;
|
||||
}
|
||||
let i = match self.list_state.selected() {
|
||||
Some(i) => if i >= self.profiles.len() - 1 { 0 } else { i + 1 },
|
||||
None => 0,
|
||||
};
|
||||
self.list_state.select(Some(i));
|
||||
}
|
||||
|
||||
/// Selects the previous profile in the list, wrapping around.
|
||||
pub fn previous(&mut self) {
|
||||
if self.profiles.is_empty() {
|
||||
self.list_state.select(None);
|
||||
return;
|
||||
}
|
||||
let i = match self.list_state.selected() {
|
||||
Some(i) => if i == 0 { self.profiles.len() - 1 } else { i - 1 },
|
||||
None => self.profiles.len() - 1,
|
||||
};
|
||||
self.list_state.select(Some(i));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
use crate::state::app::state::AppState;
|
||||
use crate::state::pages::admin::AdminState;
|
||||
|
||||
pub fn handle_admin_selection(app_state: &mut AppState) {
|
||||
pub fn handle_admin_selection(app_state: &mut AppState, admin_state: &AdminState) {
|
||||
let profiles = &app_state.profile_tree.profiles;
|
||||
if !profiles.is_empty() && app_state.general.selected_item < profiles.len() {
|
||||
app_state.selected_profile = Some(profiles[app_state.general.selected_item].name.clone());
|
||||
if let Some(selected_index) = admin_state.get_selected_index() {
|
||||
if let Some(profile) = profiles.get(selected_index) {
|
||||
app_state.selected_profile = Some(profile.name.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ pub async fn back_to_main(
|
||||
|
||||
// Reset focus state
|
||||
app_state.ui.focus_outside_canvas = false;
|
||||
app_state.general.selected_item = 0;
|
||||
app_state.focused_button_index= 0;
|
||||
|
||||
"Returned to main menu".to_string()
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ pub async fn back_to_main(
|
||||
|
||||
// Reset focus state
|
||||
app_state.ui.focus_outside_canvas = false;
|
||||
app_state.general.selected_item = 0; // Reset intro selection
|
||||
app_state.focused_button_index = 0;
|
||||
|
||||
"Returned to main menu".to_string()
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ pub fn handle_intro_selection(app_state: &mut AppState, index: usize) { // Add i
|
||||
app_state.ui.show_intro = false;
|
||||
app_state.ui.show_register = true;
|
||||
app_state.ui.focus_outside_canvas = false;
|
||||
app_state.general.selected_item = 0;
|
||||
app_state.focused_button_index = 0;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ use crate::components::{
|
||||
render_status_line,
|
||||
handlers::sidebar::{self, calculate_sidebar_layout},
|
||||
form::form::render_form,
|
||||
admin::{admin_panel::AdminPanelState},
|
||||
auth::{login::render_login, register::render_register},
|
||||
};
|
||||
use crate::config::colors::themes::Theme;
|
||||
@@ -25,6 +24,7 @@ pub fn render_ui(
|
||||
auth_state: &mut AuthState,
|
||||
login_state: &LoginState,
|
||||
register_state: &RegisterState,
|
||||
admin_state: &mut AdminState,
|
||||
theme: &Theme,
|
||||
is_edit_mode: bool,
|
||||
total_count: u64,
|
||||
@@ -68,24 +68,9 @@ pub fn render_ui(
|
||||
login_state.current_field < 2
|
||||
);
|
||||
} else if app_state.ui.show_admin {
|
||||
// Create temporary AdminPanelState for rendering
|
||||
let mut admin_state = AdminPanelState::new(
|
||||
app_state.profile_tree.profiles
|
||||
.iter()
|
||||
.map(|p| p.name.clone())
|
||||
.collect()
|
||||
);
|
||||
|
||||
// Set the selected item - FIXED
|
||||
if !admin_state.profiles.is_empty() {
|
||||
let selected_index = admin_state.get_selected_index()
|
||||
.unwrap_or(0)
|
||||
.min(admin_state.profiles.len() - 1);
|
||||
admin_state.list_state.select(Some(selected_index));
|
||||
}
|
||||
|
||||
admin_state.render(
|
||||
crate::components::admin::admin_panel::render_admin_panel(
|
||||
f,
|
||||
admin_state,
|
||||
main_content_area,
|
||||
theme,
|
||||
&app_state.profile_tree,
|
||||
|
||||
@@ -61,6 +61,7 @@ pub async fn run_ui() -> Result<(), Box<dyn std::error::Error>> {
|
||||
&mut auth_state,
|
||||
&login_state,
|
||||
®ister_state,
|
||||
&mut admin_state,
|
||||
&theme,
|
||||
is_edit_mode,
|
||||
app_state.total_count,
|
||||
|
||||
Reference in New Issue
Block a user