mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2024-12-28 18:31:17 +01:00
Added loading modal when opening styles.
This commit is contained in:
parent
7a7f2eb7de
commit
7167235146
1 changed files with 38 additions and 1 deletions
|
@ -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}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<Modal
|
||||
data-wd-key="loading-modal"
|
||||
isOpen={this.state.activeRequest}
|
||||
closeable={false}
|
||||
title={'Loading style'}
|
||||
onOpenToggle={() => this.onCancelActiveRequest()}
|
||||
>
|
||||
<p>
|
||||
Loading...
|
||||
</p>
|
||||
<p>
|
||||
<Button onClick={(e) => this.onCancelActiveRequest(e)}>
|
||||
Cancel
|
||||
</Button>
|
||||
</p>
|
||||
</Modal>
|
||||
</Modal>
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue