needs to reset the render but it finally works

This commit is contained in:
filipriec
2025-03-24 14:17:44 +01:00
parent bdb6cd4069
commit cdac78c1bc

View File

@@ -1,33 +1,87 @@
// src/modes/general/navigation.rs
// src/modes/general/navigation.rs
use crate::state::state::AppState;
use crate::ui::handlers::form::FormState;
use crate::modes::handlers::event;
pub fn move_up(app_state: &mut AppState) {
app_state.general.selected_item = app_state.general.selected_item.saturating_sub(1);
if app_state.ui.show_intro {
app_state.ui.intro_state.previous_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;
}
// Use general state for tracking selection in admin panel
if app_state.general.selected_item == 0 {
app_state.general.selected_item = profile_count - 1;
} else {
app_state.general.selected_item = app_state.general.selected_item.saturating_sub(1);
}
}
}
pub fn move_down(app_state: &mut AppState, item_count: usize) {
app_state.general.selected_item = app_state.general.selected_item.saturating_add(1);
if item_count > 0 {
app_state.general.selected_item = app_state.general.selected_item.min(item_count - 1);
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;
}
app_state.general.selected_item = (app_state.general.selected_item + 1) % profile_count;
}
}
pub fn next_option(app_state: &mut AppState, option_count: usize) {
app_state.general.current_option = app_state.general.current_option.saturating_add(1);
if option_count > 0 {
app_state.general.current_option = app_state.general.current_option.min(option_count - 1);
if app_state.ui.show_intro {
app_state.ui.intro_state.next_option();
} else {
// For other screens that might have options
app_state.general.current_option = (app_state.general.current_option + 1) % option_count;
}
}
pub fn previous_option(app_state: &mut AppState) {
app_state.general.current_option = app_state.general.current_option.saturating_sub(1);
if app_state.ui.show_intro {
app_state.ui.intro_state.previous_option();
} else {
// For other screens that might have options
if app_state.general.current_option == 0 {
// We'd need the option count here, but since it's not passed we can't wrap around correctly
// For now, just stay at 0
} else {
app_state.general.current_option -= 1;
}
}
}
pub fn select(app_state: &mut AppState) {
app_state.ui.show_form = app_state.ui.intro_state.selected_option == 0;
app_state.ui.show_admin = app_state.ui.intro_state.selected_option == 1;
app_state.ui.show_intro = false;
if app_state.ui.show_intro {
// Handle selection in intro screen
if app_state.ui.intro_state.selected_option == 0 {
// First option selected - show form
app_state.ui.show_form = true;
app_state.ui.show_admin = false;
} else {
// Second option selected - show admin
app_state.ui.show_form = false;
app_state.ui.show_admin = true;
}
app_state.ui.show_intro = false;
} else if app_state.ui.show_admin {
// Handle selection in admin panel
let profiles = &app_state.profile_tree.profiles;
if !profiles.is_empty() && app_state.general.selected_item < profiles.len() {
// Set the selected profile
app_state.selected_profile = Some(profiles[app_state.general.selected_item].name.clone());
}
}
}
pub fn toggle_sidebar(app_state: &mut AppState) {
@@ -42,25 +96,16 @@ pub fn next_field(form_state: &mut FormState) {
pub fn prev_field(form_state: &mut FormState) {
if !form_state.fields.is_empty() {
form_state.current_field = if form_state.current_field == 0 {
form_state.fields.len() - 1
if form_state.current_field == 0 {
form_state.current_field = form_state.fields.len() - 1;
} else {
form_state.current_field - 1
};
form_state.current_field -= 1;
}
}
}
pub fn handle_enter_command_mode(event_handler: &mut crate::modes::handlers::event::EventHandler) {
event_handler.command_mode = true;
event_handler.command_input.clear();
event_handler.command_message.clear();
}
// Helper function for bounds checking in lists
pub fn clamp_index(selected: usize, item_count: usize) -> usize {
if item_count == 0 {
0
} else {
selected.min(item_count - 1)
}
pub fn handle_enter_command_mode(handler: &mut event::EventHandler) {
handler.command_mode = true;
handler.command_input.clear();
handler.command_message.clear();
}