From d0f01866a10d84628fa8946d7c8471dcfd93307c Mon Sep 17 00:00:00 2001 From: Anthony Shew Date: Mon, 16 Dec 2024 15:13:41 -0700 Subject: [PATCH] WIP --- crates/turborepo-ui/src/tui/app.rs | 14 ++++++++++---- crates/turborepo-ui/src/tui/preferences.rs | 5 +++++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/crates/turborepo-ui/src/tui/app.rs b/crates/turborepo-ui/src/tui/app.rs index 0145b7ddf047f..03accdc8292c3 100644 --- a/crates/turborepo-ui/src/tui/app.rs +++ b/crates/turborepo-ui/src/tui/app.rs @@ -156,7 +156,7 @@ impl App { self.preferences.set_active_task( self.is_task_selection_pinned .then(|| active_task.to_owned()), - ); + )?; Ok(()) } @@ -167,6 +167,7 @@ impl App { self.selected_task_index = (self.selected_task_index + 1) % num_rows; self.task_list_scroll.select(Some(self.selected_task_index)); self.is_task_selection_pinned = true; + self.persist_active_task().ok(); } } @@ -180,6 +181,7 @@ impl App { .unwrap_or(num_rows - 1); self.task_list_scroll.select(Some(self.selected_task_index)); self.is_task_selection_pinned = true; + self.persist_active_task().ok(); } } @@ -816,7 +818,11 @@ fn update( app.is_task_selection_pinned = !app.is_task_selection_pinned; } Event::ToggleSidebar => { - app.has_sidebar = !app.has_sidebar; + let new_value = !app.preferences.is_task_list_visible(); + + app.preferences + .set_is_task_list_visible(Some(new_value)) + .ok(); } Event::ToggleHelpPopup => { app.showing_help_popup = !app.showing_help_popup; @@ -872,7 +878,7 @@ fn update( fn view(app: &mut App, f: &mut Frame) { let cols = app.size.pane_cols(); - let horizontal = if app.has_sidebar { + let horizontal = if app.preferences.is_task_list_visible() { Layout::horizontal([Constraint::Fill(1), Constraint::Length(cols)]) } else { Layout::horizontal([Constraint::Max(0), Constraint::Length(cols)]) @@ -886,7 +892,7 @@ fn view(app: &mut App, f: &mut Frame) { output_logs, &active_task, &app.section_focus, - app.has_sidebar, + app.preferences.is_task_list_visible(), ); let table_to_render = TaskTable::new(&app.tasks_by_status); diff --git a/crates/turborepo-ui/src/tui/preferences.rs b/crates/turborepo-ui/src/tui/preferences.rs index e58c7943e68d7..69285c183fb5a 100644 --- a/crates/turborepo-ui/src/tui/preferences.rs +++ b/crates/turborepo-ui/src/tui/preferences.rs @@ -40,6 +40,11 @@ impl PreferenceLoader { self.config.is_task_list_visible.unwrap_or(true) } + pub fn set_is_task_list_visible(&mut self, value: Option) -> Result<(), Error> { + self.config.is_task_list_visible = value; + self.flush_to_disk() + } + pub fn active_task(&self) -> Option<&str> { let active_task = self.config.active_task.as_deref()?; Some(active_task)