From ca3639bf0b29447bf079592425faea6b103ac385 Mon Sep 17 00:00:00 2001 From: Alexander Skvortsov Date: Fri, 28 Feb 2020 20:19:56 -0500 Subject: [PATCH] Use mithril props for disabling 'send test mail' button while waiting for response. --- js/src/admin/components/MailPage.js | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/js/src/admin/components/MailPage.js b/js/src/admin/components/MailPage.js index a99a160c79..facaf1527e 100644 --- a/js/src/admin/components/MailPage.js +++ b/js/src/admin/components/MailPage.js @@ -11,7 +11,7 @@ export default class MailPage extends Page { super.init(); this.saving = false; - this.sendingTest = false; + this.sendingTest = m.prop(false); this.refresh(); } @@ -127,7 +127,7 @@ export default class MailPage extends Page { type: 'button', className: 'Button Button--primary', children: app.translator.trans('core.admin.email.send_test_mail_button'), - disabled: this.sendingTestEmail(), + disabled: this.sendingTest(), onclick: () => this.sendTestEmail() }) ] @@ -162,16 +162,11 @@ export default class MailPage extends Page { return this.fields.some(key => this.values[key]() !== app.data.settings[key]); } - sendingTestEmail() { - return this.sendingTest; - } - sendTestEmail() { - if (this.saving || this.sendingTest) return; + if (this.saving || this.sendingTest()) return; - this.sendingTest = true; + this.sendingTest = m.prop(true); const settings = {}; - console.log(this.sendingTest); this.fields.forEach(key => settings[key] = this.values[key]()); @@ -180,15 +175,13 @@ export default class MailPage extends Page { url: app.forum.attribute('apiUrl') + '/mail/test', data: settings }).then(response => { - this.sendingTest = false; + this.sendingTest = m.prop(false); app.alerts.show(new Alert({ type: 'success', children: app.translator.trans('core.admin.email.send_test_mail_success') })); - this.sendingTest = false; - console.log(this.sendingTest); }).catch(error => { - this.sendingTest = false; + this.sendingTest = m.prop(false) const response = JSON.parse(error.responseText)['message']; if (Array.isArray(response)) { response.forEach(errorMessage => { @@ -210,7 +203,7 @@ export default class MailPage extends Page { onsubmit(e) { e.preventDefault(); - if (this.saving || this.sendingTest) return; + if (this.saving || this.sendingTest()) return; this.saving = true; app.alerts.dismiss(this.successAlert);