Merge pull request #398 from orangemug/fix/load-url-error

Show error if style fails to load and disabled button if input is empty
This commit is contained in:
Orange Mug 2018-09-26 18:35:51 +01:00 committed by GitHub
commit e6e2be61f0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 4 deletions

View file

@ -9,12 +9,14 @@ class Button extends React.Component {
onClick: PropTypes.func,
style: PropTypes.object,
className: PropTypes.string,
children: PropTypes.node
children: PropTypes.node,
disabled: PropTypes.bool,
}
render() {
return <button
onClick={this.props.onClick}
disabled={this.props.disabled}
aria-label={this.props["aria-label"]}
className={classnames("maputnik-button", this.props.className)}
data-wd-key={this.props["data-wd-key"]}

View file

@ -51,7 +51,9 @@ class OpenModal extends React.Component {
constructor(props) {
super(props);
this.state = {};
this.state = {
styleUrl: ""
};
}
clearError() {
@ -102,6 +104,7 @@ class OpenModal extends React.Component {
})
.catch((err) => {
this.setState({
error: `Failed to load: '${styleUrl}'`,
activeRequest: null,
activeRequestUrl: null
});
@ -150,10 +153,19 @@ class OpenModal extends React.Component {
}
onOpenToggle() {
this.setState({
styleUrl: ""
});
this.clearError();
this.props.onOpenToggle();
}
onChangeUrl = () => {
this.setState({
styleUrl: this.styleUrlElement.value
});
}
render() {
const styleOptions = publicStyles.map(style => {
return <PublicStyle
@ -197,9 +209,22 @@ class OpenModal extends React.Component {
<p>
Load from a URL. Note that the URL must have <a href="https://enable-cors.org" target="_blank" rel="noopener noreferrer">CORS enabled</a>.
</p>
<input data-wd-key="open-modal.url.input" type="text" ref={(input) => this.styleUrlElement = input} className="maputnik-input" placeholder="Enter URL..."/>
<input
data-wd-key="open-modal.url.input"
type="text"
ref={(input) => this.styleUrlElement = input}
className="maputnik-input"
placeholder="Enter URL..."
value={this.state.styleUrl}
onChange={this.onChangeUrl}
/>
<div>
<Button data-wd-key="open-modal.url.button" className="maputnik-big-button" onClick={this.onOpenUrl}>Open URL</Button>
<Button
data-wd-key="open-modal.url.button"
className="maputnik-big-button"
onClick={this.onOpenUrl}
disabled={this.state.styleUrl.length < 1}
>Open URL</Button>
</div>
</section>

View file

@ -77,6 +77,12 @@
background-color: lighten($color-midgray, 12);
color: $color-white;
}
&:disabled {
background-color: darken($color-midgray, 5);
color: $color-midgray;
cursor: not-allowed;
}
}
.maputnik-big-button {