forked from Furumi/furumi-web
Keep focus in the import wizard and drop searches after leaving details
The wizard dialog leaves the DOM without close(), so focus fell to the page body. Closing it now returns focus to the button that opened it, or to New import, unless it closes to navigate, and each new step focuses the dialog title. Leaving the details clears a pending entry search, and entries are not loaded without an import, so /api/imports/null/items is never requested. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7af037066e
commit
1ab0d3bf57
3 files changed
+87
-7
No files matched your search
@@ -172,7 +172,7 @@ document.addEventListener('alpine:init', () => {
|
||||
retryPanel: false, retryFederated: false,
|
||||
busy: false, choosing: null,
|
||||
wizard: emptyWizard(),
|
||||
_navigation: 0, _items: 0, _timer: null, _search: null, _signature: '',
|
||||
_navigation: 0, _items: 0, _timer: null, _search: null, _opener: null, _signature: '',
|
||||
|
||||
text(key, values) {
|
||||
const label = labels[key] ?? key;
|
||||
@@ -276,6 +276,8 @@ document.addEventListener('alpine:init', () => {
|
||||
},
|
||||
async enter(options = {}) {
|
||||
const token = ++this._navigation;
|
||||
clearTimeout(this._search);
|
||||
this._search = null;
|
||||
this.navigate('#imports', 'imports', options);
|
||||
this.detail = null;
|
||||
this.detailId = null;
|
||||
@@ -298,6 +300,8 @@ document.addEventListener('alpine:init', () => {
|
||||
const token = ++this._navigation;
|
||||
this.navigate('#imports/' + id, 'import_detail', options);
|
||||
if (this.detailId !== id) {
|
||||
clearTimeout(this._search);
|
||||
this._search = null;
|
||||
this.detail = null;
|
||||
this.items = [];
|
||||
this.itemsLoaded = false;
|
||||
@@ -424,6 +428,7 @@ document.addEventListener('alpine:init', () => {
|
||||
},
|
||||
async loadItems(append = false) {
|
||||
const id = this.detailId;
|
||||
if (!id) return;
|
||||
const token = ++this._items;
|
||||
this.itemsLoading = true;
|
||||
try {
|
||||
@@ -561,24 +566,40 @@ document.addEventListener('alpine:init', () => {
|
||||
// ---------------------------------------------------------------
|
||||
startWizard(provider = '') {
|
||||
Alpine.store('user').menuOpen = false;
|
||||
this._opener = document.activeElement;
|
||||
this.wizard = {...emptyWizard(), open: true, provider};
|
||||
if (!this.providersLoaded) this.loadProviders().catch(error => { this.wizard.error = error.message; });
|
||||
},
|
||||
async closeWizard(dialog) {
|
||||
// The dialog leaves the DOM without close(), so focus goes back to the
|
||||
// button that opened it, unless the wizard closes to navigate.
|
||||
async closeWizard(dialog, restoreFocus = true) {
|
||||
const opener = this._opener;
|
||||
this._opener = null;
|
||||
const close = () => {
|
||||
this.wizard = emptyWizard();
|
||||
if (restoreFocus) Alpine.nextTick(() => {
|
||||
const target = opener?.isConnected ? opener
|
||||
: document.querySelector('.library-imports .release-action-btn.primary') || document.querySelector('.library-imports h1');
|
||||
target?.focus({preventScroll: true});
|
||||
});
|
||||
};
|
||||
if (dialog) await finishPlayerDialog(dialog, close);
|
||||
else close();
|
||||
},
|
||||
// A new step replaces the focused control, so the title takes focus.
|
||||
focusWizardTitle() {
|
||||
Alpine.nextTick(() => document.getElementById('import-wizard-title')?.focus());
|
||||
},
|
||||
chooseMethod(provider, method) {
|
||||
this.wizard = {...emptyWizard(), open: true, provider, method, step: method === 'api' ? 'connect' : 'upload'};
|
||||
this.focusWizardTitle();
|
||||
// A sign-in from earlier in this session may still be valid.
|
||||
if (method === 'api') return this.loadApiPlaylists(true);
|
||||
},
|
||||
back() {
|
||||
const {provider} = this.wizard;
|
||||
this.wizard = {...emptyWizard(), open: true, provider};
|
||||
this.focusWizardTitle();
|
||||
},
|
||||
signIn(provider = this.wizard.provider) {
|
||||
location.assign(`/api/imports/providers/${encodeURIComponent(provider)}/authorize`);
|
||||
@@ -738,6 +759,7 @@ document.addEventListener('alpine:init', () => {
|
||||
}
|
||||
if (!preview.federated_search_available) wizard.federated = false;
|
||||
this.federatedAvailable = !!preview.federated_search_available;
|
||||
this.focusWizardTitle();
|
||||
},
|
||||
selectable(playlist) { return playlist.available !== false && !playlist.already_imported_in; },
|
||||
selectAll(value) {
|
||||
@@ -771,7 +793,7 @@ document.addEventListener('alpine:init', () => {
|
||||
federated_search: wizard.federated && this.federatedAvailable,
|
||||
confirm_similar: selection.filter(playlist => playlist.similar_to).map(playlist => playlist.source_key),
|
||||
})});
|
||||
await this.closeWizard(document.querySelector('.import-wizard[open]'));
|
||||
await this.closeWizard(document.querySelector('.import-wizard[open]'), false);
|
||||
return this.open(result.id);
|
||||
} catch (error) {
|
||||
if (this.wizard !== wizard) return;
|
||||
|
||||
Reference in new issue
Block a user