fix: use abort controller for modal requests

This commit is contained in:
David Ralph
2021-04-18 18:17:04 +01:00
parent 44125d7471
commit 6c4cc5c373
2 changed files with 30 additions and 5 deletions

View File

@@ -22,6 +22,7 @@ export default class BackgroundSettings extends React.PureComponent {
backgroundCategories: [window.language.modals.main.loading]
};
this.language = window.language.modals.main.settings;
this.controller = new AbortController();
}
resetCustom = () => {
@@ -70,7 +71,12 @@ export default class BackgroundSettings extends React.PureComponent {
}
async getBackgroundCategories() {
const data = await (await fetch(window.constants.API_URL + '/images/categories')).json();
const data = await (await fetch(window.constants.API_URL + '/images/categories', { signal: this.controller.signal })).json();
if (this.controller.signal.aborted === true) {
return;
}
this.setState({
backgroundCategories: data
});
@@ -80,6 +86,11 @@ export default class BackgroundSettings extends React.PureComponent {
this.getBackgroundCategories();
}
componentWillUnmount() {
// stop making requests
this.controller.abort();
}
render() {
const { background } = this.language.sections;