From 13dad89a85687a8d04af80f3b386b38aed560649 Mon Sep 17 00:00:00 2001 From: "Joseph T. Lyons" Date: Fri, 8 Dec 2023 16:08:26 -0500 Subject: [PATCH] Move all dismissal logic into dismiss_event --- crates/feedback2/src/feedback_modal.rs | 29 +++++++------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/crates/feedback2/src/feedback_modal.rs b/crates/feedback2/src/feedback_modal.rs index ed8944be06..54d0705eb3 100644 --- a/crates/feedback2/src/feedback_modal.rs +++ b/crates/feedback2/src/feedback_modal.rs @@ -245,18 +245,16 @@ impl FeedbackModal { } // TODO: Escape button calls dismiss - // TODO: Should do same as hitting cancel / clicking outside of modal - // Close immediately if no text in field - // Ask to close if text in the field fn cancel(&mut self, _: &menu::Cancel, cx: &mut ViewContext) { - Self::dismiss_event(cx) + self.dismiss_event(cx) } - fn dismiss_event(cx: &mut ViewContext) { + fn dismiss_event(&mut self, cx: &mut ViewContext) { + let has_feedback = self.feedback_editor.read(cx).text_option(cx).is_some(); let dismiss = Self::prompt_dismiss(cx); cx.spawn(|this, mut cx| async move { - if dismiss.await { + if !has_feedback || (has_feedback && dismiss.await) { this.update(&mut cx, |_, cx| cx.emit(DismissEvent)).ok(); } }) @@ -287,8 +285,6 @@ impl Render for FeedbackModal { let allow_submission = valid_character_count && valid_email_address && !self.pending_submission; - let has_feedback = self.feedback_editor.read(cx).text_option(cx).is_some(); - let submit_button_text = if self.pending_submission { "Submitting..." } else { @@ -378,19 +374,9 @@ impl Render for FeedbackModal { Button::new("cancel_feedback", "Cancel") .style(ButtonStyle::Subtle) .color(Color::Muted) - // TODO: replicate this logic when clicking outside the modal - // TODO: Will require somehow overriding the modal dismal default behavior - .map(|this| { - if has_feedback { - this.on_click(cx.listener(|_, _, cx| { - Self::dismiss_event(cx) - })) - } else { - this.on_click(cx.listener(|_, _, cx| { - cx.emit(DismissEvent); - })) - } - }), + .on_click(cx.listener(move |this, _, cx| { + this.dismiss_event(cx) + })), ) .child( Button::new("send_feedback", submit_button_text) @@ -420,3 +406,4 @@ impl Render for FeedbackModal { // TODO: Add compilation flags to enable debug mode, where we can simulate sending feedback that both succeeds and fails, so we can test the UI // TODO: Maybe store email address whenever the modal is closed, versus just on submit, so users can remove it if they want without submitting +// TODO: Fix bug of being asked twice to discard feedback when clicking cancel