mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2025-01-09 16:55:29 +00:00
Re-adds error handling code written a while back
Co-authored-by: Fabien Basmaison <contact@arkhi.org>
This commit is contained in:
parent
ad9be9f3d1
commit
909293bbb0
1 changed files with 18 additions and 2 deletions
|
@ -63,12 +63,28 @@ let StatusCache = new class {
|
||||||
submitStatus(event) {
|
submitStatus(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
const form = event.currentTarget;
|
const form = event.currentTarget;
|
||||||
|
const trigger = event.submitter;
|
||||||
|
|
||||||
BookWyrm.ajaxPost(form).catch(error => {
|
BookWyrm.addRemoveClass(form, 'is-processing', true);
|
||||||
|
trigger.setAttribute('disabled', null);
|
||||||
|
|
||||||
|
BookWyrm.ajaxPost(form).finally(() => {
|
||||||
|
// Change icon to remove ongoing activity on the current UI.
|
||||||
|
// Enable back the element used to submit the form.
|
||||||
|
BookWyrm.addRemoveClass(form, 'is-processing', false);
|
||||||
|
trigger.removeAttribute('disabled');
|
||||||
|
})
|
||||||
|
.then(this.submitStatusSuccess.bind(this, form))
|
||||||
|
.catch(error => {
|
||||||
// @todo Display a notification in the UI instead.
|
// @todo Display a notification in the UI instead.
|
||||||
|
// For now, the absence of change will be enough.
|
||||||
console.warn('Request failed:', error);
|
console.warn('Request failed:', error);
|
||||||
});
|
|
||||||
|
|
||||||
|
BookWyrm.addRemoveClass(form, 'has-error', form.className.indexOf('is-hidden') == -1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
submitStatusSuccess(form) {
|
||||||
// Clear form data
|
// Clear form data
|
||||||
form.reset();
|
form.reset();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue