mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
AddPerson search: fix aborting query when the query is altered by user
This commit is contained in:
parent
645549ae34
commit
095afb90c7
@ -45,7 +45,7 @@ const searchPersons = ({ query, options }, signal) => {
|
||||
const searchEntities = ({ query, options }, signal) => {
|
||||
let queryStr = parametersToString({ query, options });
|
||||
let url = `/api/1.0/search.json?${queryStr}`;
|
||||
return fetch(url)
|
||||
return fetch(url, { signal })
|
||||
.then(response => {
|
||||
if (response.ok) { return response.json(); }
|
||||
throw Error('Error with request resource response');
|
||||
|
@ -199,15 +199,26 @@ export default {
|
||||
return;
|
||||
}
|
||||
if (query === this.search.query) {
|
||||
if (this.currentSearchQueryController !== undefined) {
|
||||
this.currentSearchQueryController.abort()
|
||||
if (this.search.currentSearchQueryController !== null) {
|
||||
this.search.currentSearchQueryController.abort();
|
||||
}
|
||||
this.currentSearchQueryController = new AbortController();
|
||||
searchEntities({ query, options: this.options }, this.currentSearchQueryController)
|
||||
this.search.currentSearchQueryController = new AbortController();
|
||||
searchEntities({ query, options: this.options }, this.search.currentSearchQueryController.signal)
|
||||
.then(suggested => new Promise((resolve, reject) => {
|
||||
this.loadSuggestions(suggested.results);
|
||||
resolve();
|
||||
}));
|
||||
}))
|
||||
.catch(error => {
|
||||
if (error instanceof DOMException) {
|
||||
if (error.name === 'AbortError') {
|
||||
console.log('request aborted due to user continue typing');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
throw error;
|
||||
})
|
||||
;
|
||||
}
|
||||
}.bind(this), query.length > 3 ? 300 : 700);
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user