diff --git a/crates/feedback2/src/feedback_modal.rs b/crates/feedback2/src/feedback_modal.rs index 165a0a332c..d22d5d908b 100644 --- a/crates/feedback2/src/feedback_modal.rs +++ b/crates/feedback2/src/feedback_modal.rs @@ -87,6 +87,8 @@ impl EventEmitter for FeedbackModal {} impl ModalView for FeedbackModal { fn on_before_dismiss(&mut self, cx: &mut ViewContext) -> bool { + self.update_email_in_store(cx); + if self.dismiss_modal { return true; } @@ -214,21 +216,6 @@ impl FeedbackModal { cx.spawn(|this, mut cx| async move { let answer = answer.await.ok(); if answer == Some(0) { - match email.clone() { - Some(email) => { - KEY_VALUE_STORE - .write_kvp(DATABASE_KEY_NAME.to_string(), email) - .await - .ok(); - } - None => { - KEY_VALUE_STORE - .delete_kvp(DATABASE_KEY_NAME.to_string()) - .await - .ok(); - } - }; - this.update(&mut cx, |this, cx| { this.submission_state = Some(SubmissionState::CannotSubmit { reason: CannotSubmitReason::AwaitingSubmission, @@ -351,6 +338,28 @@ impl FeedbackModal { } } + fn update_email_in_store(&self, cx: &mut ViewContext) { + let email = self.email_address_editor.read(cx).text_option(cx); + + cx.spawn(|_, _| async move { + match email { + Some(email) => { + KEY_VALUE_STORE + .write_kvp(DATABASE_KEY_NAME.to_string(), email) + .await + .ok(); + } + None => { + KEY_VALUE_STORE + .delete_kvp(DATABASE_KEY_NAME.to_string()) + .await + .ok(); + } + } + }) + .detach(); + } + fn valid_email_address(&self) -> bool { !self.in_invalid_state(InvalidStateFlags::EmailAddress) } @@ -508,7 +517,6 @@ impl Render for FeedbackModal { } } -// 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: Testing of various button states, dismissal prompts, etc. // #[cfg(test)]