diff --git a/app/controllers/admin/tasks/index.js b/app/controllers/admin/tasks/index.js index cd14ab7..01ed8ef 100644 --- a/app/controllers/admin/tasks/index.js +++ b/app/controllers/admin/tasks/index.js @@ -19,9 +19,10 @@ export default class AdminTasksIndexController extends Controller { @tracked indexUids; @use - tasks = resource(() => { + tasks = resource(({ on }) => { this.tasksHolder.isLoading = true; + const controller = new AbortController(); const params = { limit: this.limit, from: this.from, @@ -30,11 +31,17 @@ export default class AdminTasksIndexController extends Controller { indexUids: this.indexUids, }; - this.meilisearch.getTasks(params).then((data) => { - this.tasksHolder.results = this.tasksHolder.results.concat(data.results); - this.tasksHolder.next = data.next; - this.tasksHolder.isLoading = false; - }); + on.cleanup(() => controller.abort()); + + this.meilisearch + .getTasks(params, { signal: controller.signal }) + .then((data) => { + this.tasksHolder.results = this.tasksHolder.results.concat( + data.results + ); + this.tasksHolder.next = data.next; + this.tasksHolder.isLoading = false; + }); return this.tasksHolder; }); diff --git a/app/utils/query.js b/app/utils/query.js index 50b7f5c..4c75a58 100644 --- a/app/utils/query.js +++ b/app/utils/query.js @@ -16,29 +16,19 @@ export default function query(path, options = {}) { Object.assign(options, { headers }) ); - return fetch(req) - .then((response) => { - if (response.status === 204) { - return; - } else if (response.ok) { - return response.json(); - } else { - return response.json().then((reason) => { - toaster.dangerToast({ - header: reason.type, - text: reason.message, - }); - - // throw new Error('Network response was not OK'); - }); - } - }) - .catch((response) => { + return fetch(req).then((response) => { + if (response.status === 204) { + return; + } else if (response.ok) { + return response.json(); + } else { return response.json().then((reason) => { toaster.dangerToast({ header: reason.type, text: reason.message, }); + // throw new Error('Network response was not OK'); }); - }); + } + }); }