From 110612bf263053db3713a61bf793f830a1abbcd7 Mon Sep 17 00:00:00 2001 From: "Joseph T. Lyons" Date: Wed, 6 Dec 2023 18:36:17 -0500 Subject: [PATCH] Reduce amount of state being stored --- crates/feedback2/src/feedback_modal.rs | 27 +++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/crates/feedback2/src/feedback_modal.rs b/crates/feedback2/src/feedback_modal.rs index ecbb242ed2f11b6ead44dc2b5c4bc0f62d8dccaf..88cee2852be5eb38a90c7760b240443fcdc5f325 100644 --- a/crates/feedback2/src/feedback_modal.rs +++ b/crates/feedback2/src/feedback_modal.rs @@ -43,8 +43,7 @@ pub struct FeedbackModal { email_address_editor: View, project: Model, character_count: usize, - allow_submission: bool, - pub pending_submission: bool, + pending_submission: bool, } impl FocusableView for FeedbackModal { @@ -134,24 +133,15 @@ impl FeedbackModal { feedback_editor, email_address_editor, project, - allow_submission: false, pending_submission: false, character_count: 0, } } pub fn submit(&mut self, cx: &mut ViewContext) -> Task> { - if !self.allow_submission { - return Task::ready(Ok(())); - } let feedback_text = self.feedback_editor.read(cx).text(cx).trim().to_string(); let email = self.email_address_editor.read(cx).text_option(cx); - if let Some(email) = email.clone() { - cx.spawn(|_, _| KEY_VALUE_STORE.write_kvp(DATABASE_KEY_NAME.to_string(), email.clone())) - .detach() - } - let answer = cx.prompt( PromptLevel::Info, "Ready to submit your feedback?", @@ -162,6 +152,12 @@ impl FeedbackModal { cx.spawn(|this, mut cx| async move { let answer = answer.await.ok(); if answer == Some(0) { + if let Some(email) = email.clone() { + let _ = KEY_VALUE_STORE + .write_kvp(DATABASE_KEY_NAME.to_string(), email) + .await; + } + this.update(&mut cx, |feedback_editor, cx| { feedback_editor.set_pending_submission(true, cx); }) @@ -241,7 +237,7 @@ impl Render for FeedbackModal { None => true, }; - self.allow_submission = FEEDBACK_CHAR_LIMIT.contains(&self.character_count) + let allow_submission = FEEDBACK_CHAR_LIMIT.contains(&self.character_count) && valid_email_address && !self.pending_submission; @@ -311,6 +307,11 @@ impl Render for FeedbackModal { Button::new("send_feedback", "Send Feedback") .color(Color::Accent) .style(ButtonStyle::Filled) + // .on_click(|_, cx| { + // cx.build_view(|cx, this| { + // FeedbackModal::submit(cx) + // }) + // }) .tooltip(|cx| { Tooltip::with_meta( "Submit feedback to the Zed team.", @@ -319,7 +320,7 @@ impl Render for FeedbackModal { cx, ) }) - .when(!self.allow_submission, |this| this.disabled(true)), + .when(!allow_submission, |this| this.disabled(true)), ), )