From e2282dcda3da00f73c2737f63bf4c10dcb144beb Mon Sep 17 00:00:00 2001 From: Adrian Papari Date: Sat, 28 Sep 2024 09:24:58 +0200 Subject: [PATCH] fix project selection #2 --- src/glim_app.rs | 10 ++++++---- src/main.rs | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/glim_app.rs b/src/glim_app.rs index 6715fa6..4bd418b 100644 --- a/src/glim_app.rs +++ b/src/glim_app.rs @@ -48,7 +48,7 @@ pub struct UiState { pub struct StatefulWidgets { pub last_frame: Duration, pub sender: Sender, - pub table_state: TableState, + pub project_table_state: TableState, pub logs_state: ListState, pub config_popup_state: Option, pub table_fade_in: Option, @@ -77,7 +77,7 @@ impl StatefulWidgets { Self { last_frame: Duration::default(), sender, - table_state: TableState::default().with_selected(0), + project_table_state: TableState::default().with_selected(0), logs_state: ListState::default().with_selected(Some(0)), table_fade_in: None, config_popup_state: None, @@ -201,16 +201,18 @@ impl StatefulWidgets { let projects = app.projects(); if projects.is_empty() { return; } - if let Some(current) = self.table_state.selected() { + if let Some(current) = self.project_table_state.selected() { let new_index = match direction { 1 => current.saturating_add(1), -1 => current.saturating_sub(1), n => panic!("invalid direction: {n}") }.min(projects.len().saturating_sub(1)); - self.table_state.select(Some(new_index)); + self.project_table_state.select(Some(new_index)); let project = &projects[new_index]; app.dispatch(GlimEvent::SelectedProject(project.id)); + } else { + self.project_table_state.select(Some(0)); } } diff --git a/src/main.rs b/src/main.rs index a38d0ce..28a85a6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -88,7 +88,7 @@ fn render_widgets( // gitlab pipelines let projects = ProjectsTable::new(app.projects()); - f.render_stateful_widget(projects, layout[0], &mut widget_states.table_state); + f.render_stateful_widget(projects, layout[0], &mut widget_states.project_table_state); // internal logs if app.ui.show_internal_logs {