diff --git a/src/components/modals/OpenModal.jsx b/src/components/modals/OpenModal.jsx index c31ffd3..f46f86f 100644 --- a/src/components/modals/OpenModal.jsx +++ b/src/components/modals/OpenModal.jsx @@ -60,13 +60,29 @@ class OpenModal extends React.Component { }) } + onCancelActiveRequest(e) { + // Else the click propagates to the underlying modal + if(e) e.stopPropagation(); + + if(this.state.activeRequest) { + this.state.activeRequest.abort(); + this.setState({ + activeRequest: null + }); + } + } + onStyleSelect(styleUrl) { this.clearError(); - request({ + const activeRequest = request({ url: styleUrl, withCredentials: false, }, (error, response, body) => { + this.setState({ + activeRequest: null + }); + if (!error && response.statusCode == 200) { const mapStyle = style.ensureStyleValidity(JSON.parse(body)) console.log('Loaded style ', mapStyle.id) @@ -76,6 +92,10 @@ class OpenModal extends React.Component { console.warn('Could not open the style URL', styleUrl) } }) + + this.setState({ + activeRequest: activeRequest + }) } onOpenUrl() { @@ -169,6 +189,23 @@ class OpenModal extends React.Component { {styleOptions} + + this.onCancelActiveRequest()} + > +

+ Loading... +

+

+ +

+
} }