Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.autosave.autosave-state-idle{ data: { controller: 'autosave-status' } }
.autosave.autosave-state-idle{ 'tabindex': '-1', data: { controller: 'autosave-status' } }
%p.autosave-explanation.fr-text--sm.fr-mb-0
%span.autosave-explanation-text
- if annotation?
Expand Down
15 changes: 15 additions & 0 deletions app/javascript/controllers/autosave_status_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export class AutosaveStatusController extends ApplicationController {
connect(): void {
this.onGlobal('autosave:enqueue', () => this.didEnqueue());
this.onGlobal('autosave:end', () => this.didSucceed());
this.onGlobal('autosave:retry', () => this.didRetry());
this.onGlobal<CustomEvent>('autosave:error', (event) =>
this.didFail(event)
);
Expand Down Expand Up @@ -55,6 +56,14 @@ export class AutosaveStatusController extends ApplicationController {
disable(this.retryButtonTarget);
}

private didRetry() {
const autosave = this.element as HTMLDivElement;
// We move focus to the success (or error) message of automatic saving
setTimeout(() => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Le délai est nécessaire pour laisser le temps au message d'enregistrement automatique d'être mis à jour avant le déplacement du focus.

autosave.focus();
}, 2000);
}

private didSucceed() {
enable(this.retryButtonTarget);
this.setState('succeeded');
Expand All @@ -74,6 +83,12 @@ export class AutosaveStatusController extends ApplicationController {
enable(this.retryButtonTarget);
this.setState('failed');

const autosave = this.element as HTMLDivElement;
// We move focus to the error message of automatic saving
setTimeout(() => {
autosave.focus();
}, 2000);

const shouldLogError = !error.response || error.response.status != 0; // ignore timeout errors
if (shouldLogError) {
this.logError(error);
Expand Down
Loading