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) => {
|
const searchEntities = ({ query, options }, signal) => {
|
||||||
let queryStr = parametersToString({ query, options });
|
let queryStr = parametersToString({ query, options });
|
||||||
let url = `/api/1.0/search.json?${queryStr}`;
|
let url = `/api/1.0/search.json?${queryStr}`;
|
||||||
return fetch(url)
|
return fetch(url, { signal })
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if (response.ok) { return response.json(); }
|
if (response.ok) { return response.json(); }
|
||||||
throw Error('Error with request resource response');
|
throw Error('Error with request resource response');
|
||||||
|
@ -199,15 +199,26 @@ export default {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (query === this.search.query) {
|
if (query === this.search.query) {
|
||||||
if (this.currentSearchQueryController !== undefined) {
|
if (this.search.currentSearchQueryController !== null) {
|
||||||
this.currentSearchQueryController.abort()
|
this.search.currentSearchQueryController.abort();
|
||||||
}
|
}
|
||||||
this.currentSearchQueryController = new AbortController();
|
this.search.currentSearchQueryController = new AbortController();
|
||||||
searchEntities({ query, options: this.options }, this.currentSearchQueryController)
|
searchEntities({ query, options: this.options }, this.search.currentSearchQueryController.signal)
|
||||||
.then(suggested => new Promise((resolve, reject) => {
|
.then(suggested => new Promise((resolve, reject) => {
|
||||||
this.loadSuggestions(suggested.results);
|
this.loadSuggestions(suggested.results);
|
||||||
resolve();
|
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);
|
}.bind(this), query.length > 3 ? 300 : 700);
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user