-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ZIP Imports: Updated import form to show loading indicator
And disable button after submit. Added here because the import could take some time, so it's best to show an indicator to the user to show that something is happening, and help prevent duplicate submission or re-submit attempts.
- Loading branch information
1 parent
c0dff6d
commit f79c6ae
Showing
4 changed files
with
45 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import {Component} from "./component.js"; | ||
import {showLoading} from "../services/dom"; | ||
import {el} from "../wysiwyg/utils/dom"; | ||
|
||
/** | ||
* Loading button. | ||
* Shows a loading indicator and disables the button when the button is clicked, | ||
* or when the form attached to the button is submitted. | ||
*/ | ||
export class LoadingButton extends Component { | ||
|
||
protected button!: HTMLButtonElement; | ||
protected loadingEl: HTMLDivElement|null = null; | ||
|
||
setup() { | ||
this.button = this.$el as HTMLButtonElement; | ||
const form = this.button.form; | ||
|
||
const action = () => { | ||
setTimeout(() => this.showLoadingState(), 10) | ||
}; | ||
|
||
this.button.addEventListener('click', action); | ||
if (form) { | ||
form.addEventListener('submit', action); | ||
} | ||
} | ||
|
||
showLoadingState() { | ||
this.button.disabled = true; | ||
|
||
if (!this.loadingEl) { | ||
this.loadingEl = el('div', {class: 'inline block'}) as HTMLDivElement; | ||
showLoading(this.loadingEl); | ||
this.button.after(this.loadingEl); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters