mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2024-11-10 06:37:45 +01:00
Merge pull request #682 from orangemug/fix/issue-681
Fix open modal URL entry to use form submission
This commit is contained in:
commit
e3e6647e03
3 changed files with 50 additions and 19 deletions
|
@ -11,10 +11,12 @@ class Button extends React.Component {
|
|||
className: PropTypes.string,
|
||||
children: PropTypes.node,
|
||||
disabled: PropTypes.bool,
|
||||
type: PropTypes.string,
|
||||
}
|
||||
|
||||
render() {
|
||||
return <button
|
||||
type={this.props.type}
|
||||
onClick={this.props.onClick}
|
||||
disabled={this.props.disabled}
|
||||
aria-label={this.props["aria-label"]}
|
||||
|
|
|
@ -1,10 +1,14 @@
|
|||
import React from 'react'
|
||||
import React, {Fragment} from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import StringInput from './StringInput'
|
||||
import SmallError from '../util/SmallError'
|
||||
|
||||
|
||||
function validate (url) {
|
||||
if (url === "") {
|
||||
return;
|
||||
}
|
||||
|
||||
let error;
|
||||
const getProtocol = (url) => {
|
||||
try {
|
||||
|
@ -16,7 +20,20 @@ function validate (url) {
|
|||
}
|
||||
};
|
||||
const protocol = getProtocol(url);
|
||||
if (
|
||||
const isSsl = window.location.protocol === "https:";
|
||||
|
||||
if (!protocol) {
|
||||
error = (
|
||||
<SmallError>
|
||||
Must provide protocol {
|
||||
isSsl
|
||||
? <code>https://</code>
|
||||
: <><code>http://</code> or <code>https://</code></>
|
||||
}
|
||||
</SmallError>
|
||||
);
|
||||
}
|
||||
else if (
|
||||
protocol &&
|
||||
protocol === "http:" &&
|
||||
window.location.protocol === "https:"
|
||||
|
@ -61,12 +78,20 @@ class UrlInput extends React.Component {
|
|||
this.props.onInput(url);
|
||||
}
|
||||
|
||||
onChange = (url) => {
|
||||
this.setState({
|
||||
error: validate(url)
|
||||
});
|
||||
this.props.onChange(url);
|
||||
}
|
||||
|
||||
render () {
|
||||
return (
|
||||
<div>
|
||||
<StringInput
|
||||
{...this.props}
|
||||
onInput={this.onInput}
|
||||
onChange={this.onChange}
|
||||
/>
|
||||
{this.state.error}
|
||||
</div>
|
||||
|
|
|
@ -123,7 +123,8 @@ class OpenModal extends React.Component {
|
|||
})
|
||||
}
|
||||
|
||||
onOpenUrl = (url) => {
|
||||
onSubmitUrl = (e) => {
|
||||
e.preventDefault();
|
||||
this.onStyleSelect(this.state.styleUrl);
|
||||
}
|
||||
|
||||
|
@ -209,22 +210,25 @@ 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>
|
||||
<UrlInput
|
||||
data-wd-key="open-modal.url.input"
|
||||
type="text"
|
||||
className="maputnik-input"
|
||||
default="Enter URL..."
|
||||
value={this.state.styleUrl}
|
||||
onInput={this.onChangeUrl}
|
||||
/>
|
||||
<div>
|
||||
<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>
|
||||
<form onSubmit={this.onSubmitUrl}>
|
||||
<UrlInput
|
||||
data-wd-key="open-modal.url.input"
|
||||
type="text"
|
||||
className="maputnik-input"
|
||||
default="Enter URL..."
|
||||
value={this.state.styleUrl}
|
||||
onInput={this.onChangeUrl}
|
||||
onChange={this.onChangeUrl}
|
||||
/>
|
||||
<div>
|
||||
<Button
|
||||
data-wd-key="open-modal.url.button"
|
||||
type="submit"
|
||||
className="maputnik-big-button"
|
||||
disabled={this.state.styleUrl.length < 1}
|
||||
>Open URL</Button>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
<section className="maputnik-modal-section maputnik-modal-section--shrink">
|
||||
|
|
Loading…
Reference in a new issue