mirror of
https://github.com/a-nyx/maputnik-with-pmtiles.git
synced 2025-01-15 02:53:27 +01:00
Fix modal rendering and simplify
This commit is contained in:
parent
e32f3bb06e
commit
b874d9864d
3 changed files with 43 additions and 41 deletions
|
@ -25,7 +25,7 @@ export default class App extends React.Component {
|
||||||
console.log('Falling back to local storage for storing styles')
|
console.log('Falling back to local storage for storing styles')
|
||||||
this.styleStore = new StyleStore()
|
this.styleStore = new StyleStore()
|
||||||
}
|
}
|
||||||
this.styleStore.latestStyle(mapStyle => this.onStyleUpload(mapStyle))
|
this.styleStore.latestStyle(mapStyle => this.onStyleOpen(mapStyle))
|
||||||
})
|
})
|
||||||
|
|
||||||
this.settingsStore = new SettingsStore()
|
this.settingsStore = new SettingsStore()
|
||||||
|
@ -38,7 +38,7 @@ export default class App extends React.Component {
|
||||||
|
|
||||||
onReset() {
|
onReset() {
|
||||||
this.styleStore.purge()
|
this.styleStore.purge()
|
||||||
loadDefaultStyle(mapStyle => this.onStyleUpload(mapStyle))
|
loadDefaultStyle(mapStyle => this.onStyleOpen(mapStyle))
|
||||||
}
|
}
|
||||||
|
|
||||||
onStyleDownload() {
|
onStyleDownload() {
|
||||||
|
@ -48,7 +48,7 @@ export default class App extends React.Component {
|
||||||
this.onStyleSave()
|
this.onStyleSave()
|
||||||
}
|
}
|
||||||
|
|
||||||
onStyleUpload(newStyle) {
|
onStyleOpen(newStyle) {
|
||||||
console.log('upload', newStyle)
|
console.log('upload', newStyle)
|
||||||
const savedStyle = this.styleStore.save(newStyle)
|
const savedStyle = this.styleStore.save(newStyle)
|
||||||
this.setState({ mapStyle: savedStyle })
|
this.setState({ mapStyle: savedStyle })
|
||||||
|
@ -130,7 +130,7 @@ export default class App extends React.Component {
|
||||||
mapStyle={this.state.mapStyle}
|
mapStyle={this.state.mapStyle}
|
||||||
onStyleChanged={this.onStyleChanged.bind(this)}
|
onStyleChanged={this.onStyleChanged.bind(this)}
|
||||||
onStyleSave={this.onStyleSave.bind(this)}
|
onStyleSave={this.onStyleSave.bind(this)}
|
||||||
onStyleUpload={this.onStyleUpload.bind(this)}
|
onStyleOpen={this.onStyleOpen.bind(this)}
|
||||||
onStyleDownload={this.onStyleDownload.bind(this)}
|
onStyleDownload={this.onStyleDownload.bind(this)}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,7 @@ export default class Toolbar extends React.Component {
|
||||||
mapStyle: React.PropTypes.object.isRequired,
|
mapStyle: React.PropTypes.object.isRequired,
|
||||||
onStyleChanged: React.PropTypes.func.isRequired,
|
onStyleChanged: React.PropTypes.func.isRequired,
|
||||||
// A new style has been uploaded
|
// A new style has been uploaded
|
||||||
onStyleUpload: React.PropTypes.func.isRequired,
|
onStyleOpen: React.PropTypes.func.isRequired,
|
||||||
// Current style is requested for download
|
// Current style is requested for download
|
||||||
onStyleDownload: React.PropTypes.func.isRequired,
|
onStyleDownload: React.PropTypes.func.isRequired,
|
||||||
// Style is explicitely saved to local cache
|
// Style is explicitely saved to local cache
|
||||||
|
@ -86,9 +86,11 @@ export default class Toolbar extends React.Component {
|
||||||
constructor(props) {
|
constructor(props) {
|
||||||
super(props)
|
super(props)
|
||||||
this.state = {
|
this.state = {
|
||||||
openSettingsModal: false,
|
isOpen: {
|
||||||
openSourcesModal: false,
|
settings: false,
|
||||||
openOpenModal: false,
|
sources: false,
|
||||||
|
open: false,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -99,16 +101,35 @@ export default class Toolbar extends React.Component {
|
||||||
</ToolbarAction>
|
</ToolbarAction>
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleSettings() {
|
toggleModal(modalName) {
|
||||||
this.setState({openSettingsModal: !this.state.openSettingsModal})
|
this.setState({
|
||||||
|
isOpen: {
|
||||||
|
...this.state.isOpen,
|
||||||
|
[modalName]: !this.state.isOpen[modalName]
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
toggleSources() {
|
renderModals() {
|
||||||
this.setState({openSourcesModal: !this.state.openSourcesModal})
|
return [
|
||||||
}
|
<SettingsModal
|
||||||
|
mapStyle={this.props.mapStyle}
|
||||||
toggleOpen() {
|
onStyleChanged={this.props.onStyleChanged}
|
||||||
this.setState({openOpenModal: !this.state.openOpenModal})
|
isOpen={this.state.isOpen.settings}
|
||||||
|
onOpenToggle={this.toggleModal.bind(this, 'settings')}
|
||||||
|
/>,
|
||||||
|
<OpenModal
|
||||||
|
isOpen={this.state.isOpen.open}
|
||||||
|
onStyleOpen={this.props.onStyleOpen}
|
||||||
|
onOpenToggle={this.toggleModal.bind(this, 'open')}
|
||||||
|
/>,
|
||||||
|
<SourcesModal
|
||||||
|
mapStyle={this.props.mapStyle}
|
||||||
|
onStyleChanged={this.props.onStyleChanged}
|
||||||
|
isOpen={this.state.isOpen.sources}
|
||||||
|
onOpenToggle={this.toggleModal.bind(this, 'sources')}
|
||||||
|
/>,
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
@ -121,26 +142,7 @@ export default class Toolbar extends React.Component {
|
||||||
top: 0,
|
top: 0,
|
||||||
backgroundColor: colors.black
|
backgroundColor: colors.black
|
||||||
}}>
|
}}>
|
||||||
{this.state.openSettingsModal && <SettingsModal
|
{this.renderModals()}
|
||||||
mapStyle={this.props.mapStyle}
|
|
||||||
onStyleChanged={this.props.onStyleChanged}
|
|
||||||
isOpen={this.state.openSettingsModal}
|
|
||||||
onToggleOpen={this.toggleSettings.bind(this)}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
{this.state.openOpenModal &&<OpenModal
|
|
||||||
isOpen={this.state.openOpenModal}
|
|
||||||
onStyleOpen={this.props.onStyleUpload}
|
|
||||||
onToggleOpen={this.toggleOpen.bind(this)}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
{this.state.openSourcesModal && <SourcesModal
|
|
||||||
mapStyle={this.props.mapStyle}
|
|
||||||
onStyleChanged={this.props.onStyleChanged}
|
|
||||||
isOpen={this.state.openSourcesModal}
|
|
||||||
onToggleOpen={this.toggleSources.bind(this)}
|
|
||||||
/>
|
|
||||||
}
|
|
||||||
<ToolbarLink
|
<ToolbarLink
|
||||||
href={"https://github.com/maputnik/editor"}
|
href={"https://github.com/maputnik/editor"}
|
||||||
style={{
|
style={{
|
||||||
|
@ -153,20 +155,20 @@ export default class Toolbar extends React.Component {
|
||||||
<img src="https://github.com/maputnik/editor/raw/master/media/maputnik.png" alt="Maputnik" style={{width: 30, height: 30, paddingRight: 5, verticalAlign: 'middle'}}/>
|
<img src="https://github.com/maputnik/editor/raw/master/media/maputnik.png" alt="Maputnik" style={{width: 30, height: 30, paddingRight: 5, verticalAlign: 'middle'}}/>
|
||||||
<span style={{fontSize: 20, verticalAlign: 'middle' }}>Maputnik</span>
|
<span style={{fontSize: 20, verticalAlign: 'middle' }}>Maputnik</span>
|
||||||
</ToolbarLink>
|
</ToolbarLink>
|
||||||
<ToolbarAction onClick={this.toggleOpen.bind(this)}>
|
<ToolbarAction onClick={this.toggleModal.bind(this, 'open')}>
|
||||||
<MdOpenInBrowser />
|
<MdOpenInBrowser />
|
||||||
<IconText>Open</IconText>
|
<IconText>Open</IconText>
|
||||||
</ToolbarAction>
|
</ToolbarAction>
|
||||||
{this.downloadButton()}
|
{this.downloadButton()}
|
||||||
<ToolbarAction onClick={this.toggleSources.bind(this)}>
|
<ToolbarAction onClick={this.toggleModal.bind(this, 'sources')}>
|
||||||
<MdLayers />
|
<MdLayers />
|
||||||
<IconText>Sources</IconText>
|
<IconText>Sources</IconText>
|
||||||
</ToolbarAction>
|
</ToolbarAction>
|
||||||
<ToolbarAction onClick={this.toggleSettings.bind(this)}>
|
<ToolbarAction onClick={this.toggleModal.bind(this, 'settings')}>
|
||||||
<MdSettings />
|
<MdSettings />
|
||||||
<IconText>Style Settings</IconText>
|
<IconText>Style Settings</IconText>
|
||||||
</ToolbarAction>
|
</ToolbarAction>
|
||||||
<ToolbarAction onClick={this.toggleSettings.bind(this)}>
|
<ToolbarAction onClick={this.toggleModal.bind(this, 'settings')}>
|
||||||
<MdFindInPage />
|
<MdFindInPage />
|
||||||
<IconText>Inspect</IconText>
|
<IconText>Inspect</IconText>
|
||||||
</ToolbarAction>
|
</ToolbarAction>
|
||||||
|
|
|
@ -31,7 +31,7 @@ class Modal extends React.Component {
|
||||||
{this.props.title}
|
{this.props.title}
|
||||||
<span style={{flexGrow: 1}} />
|
<span style={{flexGrow: 1}} />
|
||||||
<a
|
<a
|
||||||
onClick={this.props.toggleOpen(false)}
|
onClick={() => this.props.onOpenToggle(false)}
|
||||||
style={{ cursor: 'pointer' }} >
|
style={{ cursor: 'pointer' }} >
|
||||||
<CloseIcon />
|
<CloseIcon />
|
||||||
</a>
|
</a>
|
||||||
|
|
Loading…
Reference in a new issue