mirror of
https://github.com/mue/mue.git
synced 2026-07-24 17:27:17 +02:00
fix: use abort controller for modal requests
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user