diff --git a/src/components/modals/OpenModal.jsx b/src/components/modals/OpenModal.jsx index 5d9901f..85794e3 100644 --- a/src/components/modals/OpenModal.jsx +++ b/src/components/modals/OpenModal.jsx @@ -76,6 +76,8 @@ class OpenModal extends React.Component { onStyleSelect = (styleUrl) => { this.clearError(); + let canceled; + const activeRequest = fetch(styleUrl, { mode: 'cors', credentials: "same-origin" @@ -84,6 +86,10 @@ class OpenModal extends React.Component { return response.json(); }) .then((body) => { + if(canceled) { + return; + } + this.setState({ activeRequest: null, activeRequestUrl: null @@ -104,7 +110,11 @@ class OpenModal extends React.Component { }) this.setState({ - activeRequest: activeRequest, + activeRequest: { + abort: function() { + canceled = true; + } + }, activeRequestUrl: styleUrl }) } @@ -165,49 +175,53 @@ class OpenModal extends React.Component { ); } - return this.onOpenToggle()} - title={'Open Style'} - > - {errorElement} -
-

Upload Style

-

Upload a JSON style from your computer.

- - - -
+ return ( +
+ this.onOpenToggle()} + title={'Open Style'} + > + {errorElement} +
+

Upload Style

+

Upload a JSON style from your computer.

+ + + +
-
-

Load from URL

-

- Load from a URL. Note that the URL must have CORS enabled. -

- this.styleUrlElement = input} className="maputnik-input" placeholder="Enter URL..."/> -
- -
-
+
+

Load from URL

+

+ Load from a URL. Note that the URL must have CORS enabled. +

+ this.styleUrlElement = input} className="maputnik-input" placeholder="Enter URL..."/> +
+ +
+
-
-

Gallery Styles

-

- Open one of the publicly available styles to start from. -

-
- {styleOptions} -
-
+
+

Gallery Styles

+

+ Open one of the publicly available styles to start from. +

+
+ {styleOptions} +
+
+
- this.onCancelActiveRequest(e)} - message={"Loading: "+this.state.activeRequestUrl} - /> - + this.onCancelActiveRequest(e)} + message={"Loading: "+this.state.activeRequestUrl} + /> +
+ ) } }