diff --git a/crates/ely_app/src/shell/internal_pages/downloads.rs b/crates/ely_app/src/shell/internal_pages/downloads.rs index af5f92b..5b11931 100644 --- a/crates/ely_app/src/shell/internal_pages/downloads.rs +++ b/crates/ely_app/src/shell/internal_pages/downloads.rs @@ -58,9 +58,35 @@ impl ElyShell { .flex_col() .items_end() .gap_1() - .child(div().text_xs().text_color(rgb(colors::MUTED)).child( - format!("{} downloads", snapshot.download_entries.len()), - )) + .child( + div() + .flex() + .items_center() + .gap_2() + .child( + div().text_xs().text_color(rgb(colors::MUTED)).child( + format!( + "{} downloads", + snapshot.download_entries.len() + ), + ), + ) + .when(!snapshot.download_entries.is_empty(), |this| { + this.child( + Button::new("clear-downloads") + .ghost() + .xsmall() + .icon(IconName::Delete) + .tooltip("Clear Downloads") + .on_click(cx.listener(|shell, _, _, cx| { + shell + .request_clear_active_profile_downloads( + cx, + ); + })), + ) + }), + ) .child( div() .flex() @@ -78,10 +104,63 @@ impl ElyShell { .when_some(self.download_file_error.clone(), |this, message| { this.child(render_download_file_error(message)) }) + .when( + self.download_clear_confirmation && !snapshot.download_entries.is_empty(), + |this| this.child(self.render_download_clear_confirmation(snapshot, cx)), + ) .child(self.render_downloads_list(snapshot, cx)), ) } + fn render_download_clear_confirmation( + &mut self, + snapshot: &BrowserSnapshot, + cx: &mut Context, + ) -> AnyElement { + div() + .rounded_md() + .border_1() + .border_color(rgb(colors::HAIRLINE)) + .px_3() + .py_2() + .flex() + .items_center() + .justify_between() + .gap_3() + .child(div().min_w_0().text_xs().text_color(rgb(colors::BODY)).truncate().child( + format!( + "Clear {} downloads for {}?", + snapshot.download_entries.len(), + snapshot.active_profile_name + ), + )) + .child( + div() + .flex() + .items_center() + .gap_2() + .child( + Button::new("cancel-clear-downloads") + .ghost() + .xsmall() + .label("Cancel") + .on_click(cx.listener(|shell, _, _, cx| { + shell.cancel_clear_active_profile_downloads(cx); + })), + ) + .child( + Button::new("confirm-clear-downloads") + .danger() + .xsmall() + .label("Clear") + .on_click(cx.listener(|shell, _, _, cx| { + shell.clear_active_profile_downloads(cx); + })), + ), + ) + .into_any_element() + } + fn render_downloads_list( &mut self, snapshot: &BrowserSnapshot, diff --git a/crates/ely_app/src/shell/mod.rs b/crates/ely_app/src/shell/mod.rs index f6c26bf..5fd8101 100644 --- a/crates/ely_app/src/shell/mod.rs +++ b/crates/ely_app/src/shell/mod.rs @@ -23,6 +23,7 @@ pub struct ElyShell { command_input: Entity, last_intent: Option, download_file_error: Option, + download_clear_confirmation: bool, _command_subscription: Subscription, } @@ -79,6 +80,7 @@ impl ElyShell { command_input, last_intent: None, download_file_error: None, + download_clear_confirmation: false, _command_subscription: command_subscription, } } @@ -249,6 +251,25 @@ impl ElyShell { } } + fn request_clear_active_profile_downloads(&mut self, cx: &mut Context) { + self.download_clear_confirmation = true; + cx.notify(); + } + + fn cancel_clear_active_profile_downloads(&mut self, cx: &mut Context) { + self.download_clear_confirmation = false; + cx.notify(); + } + + fn clear_active_profile_downloads(&mut self, cx: &mut Context) { + if let ShellState::Ready(core) = &mut self.state { + core.clear_downloads_for_active_profile(); + } + self.download_clear_confirmation = false; + self.download_file_error = None; + cx.notify(); + } + fn open_download_file(&mut self, download_id: &DownloadId, cx: &mut Context) { self.run_download_file_action(download_id, DownloadFileAction::Open, cx); }