Skip to content

Commit f79c6ae

Browse files
committed
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.
1 parent c0dff6d commit f79c6ae

File tree

4 files changed

+45
-2
lines changed

4 files changed

+45
-2
lines changed

resources/js/components/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export {HeaderMobileToggle} from './header-mobile-toggle';
3030
export {ImageManager} from './image-manager';
3131
export {ImagePicker} from './image-picker';
3232
export {ListSortControl} from './list-sort-control';
33+
export {LoadingButton} from './loading-button';
3334
export {MarkdownEditor} from './markdown-editor';
3435
export {NewUserPassword} from './new-user-password';
3536
export {Notification} from './notification';
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import {Component} from "./component.js";
2+
import {showLoading} from "../services/dom";
3+
import {el} from "../wysiwyg/utils/dom";
4+
5+
/**
6+
* Loading button.
7+
* Shows a loading indicator and disables the button when the button is clicked,
8+
* or when the form attached to the button is submitted.
9+
*/
10+
export class LoadingButton extends Component {
11+
12+
protected button!: HTMLButtonElement;
13+
protected loadingEl: HTMLDivElement|null = null;
14+
15+
setup() {
16+
this.button = this.$el as HTMLButtonElement;
17+
const form = this.button.form;
18+
19+
const action = () => {
20+
setTimeout(() => this.showLoadingState(), 10)
21+
};
22+
23+
this.button.addEventListener('click', action);
24+
if (form) {
25+
form.addEventListener('submit', action);
26+
}
27+
}
28+
29+
showLoadingState() {
30+
this.button.disabled = true;
31+
32+
if (!this.loadingEl) {
33+
this.loadingEl = el('div', {class: 'inline block'}) as HTMLDivElement;
34+
showLoading(this.loadingEl);
35+
this.button.after(this.loadingEl);
36+
}
37+
}
38+
}

resources/sass/styles.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ $loadingSize: 10px;
106106
}
107107
}
108108

109+
.inline.block .loading-container {
110+
margin: $-xs $-s;
111+
}
112+
109113
.skip-to-content-link {
110114
position: fixed;
111115
top: -52px;

resources/views/exports/import-show.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
])
6060
@endif
6161

62-
<div class="text-right">
62+
<div class="flex-container-row items-center justify-flex-end">
6363
<a href="{{ url('/import') }}" class="button outline">{{ trans('common.cancel') }}</a>
6464
<div component="dropdown" class="inline block mx-s">
6565
<button refs="dropdown@toggle"
@@ -72,7 +72,7 @@ class="button outline">{{ trans('common.delete') }}</button>
7272
<button type="submit" form="import-delete-form" class="text-link small text-item">{{ trans('common.confirm') }}</button>
7373
</div>
7474
</div>
75-
<button type="submit" class="button">{{ trans('entities.import_run') }}</button>
75+
<button component="loading-button" type="submit" class="button">{{ trans('entities.import_run') }}</button>
7676
</div>
7777
</form>
7878
</main>

0 commit comments

Comments
 (0)