Reduce amount of state being stored
This commit is contained in:
parent
46c998ca8d
commit
110612bf26
1 changed files with 14 additions and 13 deletions
|
@ -43,8 +43,7 @@ pub struct FeedbackModal {
|
||||||
email_address_editor: View<Editor>,
|
email_address_editor: View<Editor>,
|
||||||
project: Model<Project>,
|
project: Model<Project>,
|
||||||
character_count: usize,
|
character_count: usize,
|
||||||
allow_submission: bool,
|
pending_submission: bool,
|
||||||
pub pending_submission: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FocusableView for FeedbackModal {
|
impl FocusableView for FeedbackModal {
|
||||||
|
@ -134,24 +133,15 @@ impl FeedbackModal {
|
||||||
feedback_editor,
|
feedback_editor,
|
||||||
email_address_editor,
|
email_address_editor,
|
||||||
project,
|
project,
|
||||||
allow_submission: false,
|
|
||||||
pending_submission: false,
|
pending_submission: false,
|
||||||
character_count: 0,
|
character_count: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn submit(&mut self, cx: &mut ViewContext<Self>) -> Task<anyhow::Result<()>> {
|
pub fn submit(&mut self, cx: &mut ViewContext<Self>) -> Task<anyhow::Result<()>> {
|
||||||
if !self.allow_submission {
|
|
||||||
return Task::ready(Ok(()));
|
|
||||||
}
|
|
||||||
let feedback_text = self.feedback_editor.read(cx).text(cx).trim().to_string();
|
let feedback_text = self.feedback_editor.read(cx).text(cx).trim().to_string();
|
||||||
let email = self.email_address_editor.read(cx).text_option(cx);
|
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(
|
let answer = cx.prompt(
|
||||||
PromptLevel::Info,
|
PromptLevel::Info,
|
||||||
"Ready to submit your feedback?",
|
"Ready to submit your feedback?",
|
||||||
|
@ -162,6 +152,12 @@ impl FeedbackModal {
|
||||||
cx.spawn(|this, mut cx| async move {
|
cx.spawn(|this, mut cx| async move {
|
||||||
let answer = answer.await.ok();
|
let answer = answer.await.ok();
|
||||||
if answer == Some(0) {
|
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| {
|
this.update(&mut cx, |feedback_editor, cx| {
|
||||||
feedback_editor.set_pending_submission(true, cx);
|
feedback_editor.set_pending_submission(true, cx);
|
||||||
})
|
})
|
||||||
|
@ -241,7 +237,7 @@ impl Render for FeedbackModal {
|
||||||
None => true,
|
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
|
&& valid_email_address
|
||||||
&& !self.pending_submission;
|
&& !self.pending_submission;
|
||||||
|
|
||||||
|
@ -311,6 +307,11 @@ impl Render for FeedbackModal {
|
||||||
Button::new("send_feedback", "Send Feedback")
|
Button::new("send_feedback", "Send Feedback")
|
||||||
.color(Color::Accent)
|
.color(Color::Accent)
|
||||||
.style(ButtonStyle::Filled)
|
.style(ButtonStyle::Filled)
|
||||||
|
// .on_click(|_, cx| {
|
||||||
|
// cx.build_view(|cx, this| {
|
||||||
|
// FeedbackModal::submit(cx)
|
||||||
|
// })
|
||||||
|
// })
|
||||||
.tooltip(|cx| {
|
.tooltip(|cx| {
|
||||||
Tooltip::with_meta(
|
Tooltip::with_meta(
|
||||||
"Submit feedback to the Zed team.",
|
"Submit feedback to the Zed team.",
|
||||||
|
@ -319,7 +320,7 @@ impl Render for FeedbackModal {
|
||||||
cx,
|
cx,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
.when(!self.allow_submission, |this| this.disabled(true)),
|
.when(!allow_submission, |this| this.disabled(true)),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue