Skip to content

Commit

Permalink
fix project selection #2
Browse files Browse the repository at this point in the history
  • Loading branch information
junkdog committed Sep 28, 2024
1 parent 53052ad commit e2282dc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions src/glim_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub struct UiState {
pub struct StatefulWidgets {
pub last_frame: Duration,
pub sender: Sender<GlimEvent>,
pub table_state: TableState,
pub project_table_state: TableState,
pub logs_state: ListState,
pub config_popup_state: Option<ConfigPopupState>,
pub table_fade_in: Option<Effect>,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit e2282dc

Please sign in to comment.