import React from 'react'
import Modal from './Modal'
import Button from '../Button'
import FileReaderInput from 'react-file-reader-input'
import request from 'request'
import FileUploadIcon from 'react-icons/lib/md/file-upload'
import AddIcon from 'react-icons/lib/md/add-circle-outline'
import style from '../../libs/style.js'
import publicStyles from '../../config/styles.json'
class PublicStyle extends React.Component {
static propTypes = {
url: React.PropTypes.string.isRequired,
thumbnailUrl: React.PropTypes.string.isRequired,
title: React.PropTypes.string.isRequired,
onSelect: React.PropTypes.func.isRequired,
}
render() {
return
}
}
class OpenModal extends React.Component {
static propTypes = {
isOpen: React.PropTypes.bool.isRequired,
onOpenToggle: React.PropTypes.func.isRequired,
onStyleOpen: React.PropTypes.func.isRequired,
}
onStyleSelect(styleUrl) {
request({
url: styleUrl,
withCredentials: false,
}, (error, response, body) => {
if (!error && response.statusCode == 200) {
const mapStyle = style.ensureStyleValidity(JSON.parse(body))
console.log('Loaded style ', mapStyle.id)
this.props.onStyleOpen(mapStyle)
} else {
console.warn('Could not open the style URL', styleUrl)
}
})
}
onUpload(_, files) {
const [e, file] = files[0];
const reader = new FileReader();
reader.readAsText(file, "UTF-8");
reader.onload = e => {
let mapStyle = JSON.parse(e.target.result)
mapStyle = style.ensureStyleValidity(mapStyle)
this.props.onStyleOpen(mapStyle);
}
reader.onerror = e => console.log(e.target);
}
render() {
const styleOptions = publicStyles.map(style => {
return
})
return
Upload Style
Upload a JSON style from your computer.
Gallery Styles
Open one of the publicly available styles to start from.
{styleOptions}
}
}
export default OpenModal