From c8b3c4c6cd82f7c60776c13ea82aac906eee3a3f Mon Sep 17 00:00:00 2001 From: Marshall Bowers Date: Thu, 5 Dec 2024 15:57:35 -0500 Subject: [PATCH] assistant2: Add ability to delete past threads (#21607) This PR adds the ability to delete past threads in Assistant2. Release Notes: - N/A --- crates/assistant2/src/assistant_panel.rs | 9 +++++++-- crates/assistant2/src/thread_history.rs | 14 +++++++++++++- crates/assistant2/src/thread_store.rs | 4 ++++ 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/crates/assistant2/src/assistant_panel.rs b/crates/assistant2/src/assistant_panel.rs index 2d9f563c2f6817fca5318fbfa2a5c2456e154739..fde3aa02bad6cebe963534b11d9f7af2b15a5102 100644 --- a/crates/assistant2/src/assistant_panel.rs +++ b/crates/assistant2/src/assistant_panel.rs @@ -106,6 +106,10 @@ impl AssistantPanel { } } + pub(crate) fn local_timezone(&self) -> UtcOffset { + self.local_timezone + } + fn new_thread(&mut self, cx: &mut ViewContext) { let thread = self .thread_store @@ -147,8 +151,9 @@ impl AssistantPanel { self.message_editor.focus_handle(cx).focus(cx); } - pub(crate) fn local_timezone(&self) -> UtcOffset { - self.local_timezone + pub(crate) fn delete_thread(&mut self, thread_id: &ThreadId, cx: &mut ViewContext) { + self.thread_store + .update(cx, |this, cx| this.delete_thread(thread_id, cx)); } } diff --git a/crates/assistant2/src/thread_history.rs b/crates/assistant2/src/thread_history.rs index 7216ca695a77750eaaed31193205673673dcf418..f183276f7b575b22c7e7b4f557e7983c1abf0368 100644 --- a/crates/assistant2/src/thread_history.rs +++ b/crates/assistant2/src/thread_history.rs @@ -127,11 +127,23 @@ impl RenderOnce for PastThread { .child( IconButton::new("delete", IconName::TrashAlt) .shape(IconButtonShape::Square) - .icon_size(IconSize::Small), + .icon_size(IconSize::Small) + .on_click({ + let assistant_panel = self.assistant_panel.clone(); + let id = id.clone(); + move |_event, cx| { + assistant_panel + .update(cx, |this, cx| { + this.delete_thread(&id, cx); + }) + .ok(); + } + }), ), ) .on_click({ let assistant_panel = self.assistant_panel.clone(); + let id = id.clone(); move |_event, cx| { assistant_panel .update(cx, |this, cx| { diff --git a/crates/assistant2/src/thread_store.rs b/crates/assistant2/src/thread_store.rs index 7ceee9306b9c05b912188a6102c9bf772794d8b8..94cb72ce430a416c140dd7933725172bb524bff7 100644 --- a/crates/assistant2/src/thread_store.rs +++ b/crates/assistant2/src/thread_store.rs @@ -80,6 +80,10 @@ impl ThreadStore { .cloned() } + pub fn delete_thread(&mut self, id: &ThreadId, cx: &mut ModelContext) { + self.threads.retain(|thread| thread.read(cx).id() != id); + } + fn register_context_server_handlers(&self, cx: &mut ModelContext) { cx.subscribe( &self.context_server_manager.clone(),