From b874d9864db914771355156274256db56c2ed307 Mon Sep 17 00:00:00 2001 From: Lukas Martinelli Date: Thu, 22 Dec 2016 16:51:18 +0100 Subject: [PATCH] Fix modal rendering and simplify --- src/components/App.jsx | 8 ++-- src/components/Toolbar.jsx | 74 +++++++++++++++++---------------- src/components/modals/Modal.jsx | 2 +- 3 files changed, 43 insertions(+), 41 deletions(-) diff --git a/src/components/App.jsx b/src/components/App.jsx index 6b0992e..7c71356 100644 --- a/src/components/App.jsx +++ b/src/components/App.jsx @@ -25,7 +25,7 @@ export default class App extends React.Component { console.log('Falling back to local storage for storing styles') this.styleStore = new StyleStore() } - this.styleStore.latestStyle(mapStyle => this.onStyleUpload(mapStyle)) + this.styleStore.latestStyle(mapStyle => this.onStyleOpen(mapStyle)) }) this.settingsStore = new SettingsStore() @@ -38,7 +38,7 @@ export default class App extends React.Component { onReset() { this.styleStore.purge() - loadDefaultStyle(mapStyle => this.onStyleUpload(mapStyle)) + loadDefaultStyle(mapStyle => this.onStyleOpen(mapStyle)) } onStyleDownload() { @@ -48,7 +48,7 @@ export default class App extends React.Component { this.onStyleSave() } - onStyleUpload(newStyle) { + onStyleOpen(newStyle) { console.log('upload', newStyle) const savedStyle = this.styleStore.save(newStyle) this.setState({ mapStyle: savedStyle }) @@ -130,7 +130,7 @@ export default class App extends React.Component { mapStyle={this.state.mapStyle} onStyleChanged={this.onStyleChanged.bind(this)} onStyleSave={this.onStyleSave.bind(this)} - onStyleUpload={this.onStyleUpload.bind(this)} + onStyleOpen={this.onStyleOpen.bind(this)} onStyleDownload={this.onStyleDownload.bind(this)} /> diff --git a/src/components/Toolbar.jsx b/src/components/Toolbar.jsx index f82224b..872ad9d 100644 --- a/src/components/Toolbar.jsx +++ b/src/components/Toolbar.jsx @@ -76,7 +76,7 @@ export default class Toolbar extends React.Component { mapStyle: React.PropTypes.object.isRequired, onStyleChanged: React.PropTypes.func.isRequired, // A new style has been uploaded - onStyleUpload: React.PropTypes.func.isRequired, + onStyleOpen: React.PropTypes.func.isRequired, // Current style is requested for download onStyleDownload: React.PropTypes.func.isRequired, // Style is explicitely saved to local cache @@ -86,9 +86,11 @@ export default class Toolbar extends React.Component { constructor(props) { super(props) this.state = { - openSettingsModal: false, - openSourcesModal: false, - openOpenModal: false, + isOpen: { + settings: false, + sources: false, + open: false, + } } } @@ -99,16 +101,35 @@ export default class Toolbar extends React.Component { } - toggleSettings() { - this.setState({openSettingsModal: !this.state.openSettingsModal}) + toggleModal(modalName) { + this.setState({ + isOpen: { + ...this.state.isOpen, + [modalName]: !this.state.isOpen[modalName] + } + }) } - toggleSources() { - this.setState({openSourcesModal: !this.state.openSourcesModal}) - } - - toggleOpen() { - this.setState({openOpenModal: !this.state.openOpenModal}) + renderModals() { + return [ + , + , + , + ] } render() { @@ -121,26 +142,7 @@ export default class Toolbar extends React.Component { top: 0, backgroundColor: colors.black }}> - {this.state.openSettingsModal && - } - {this.state.openOpenModal && - } - {this.state.openSourcesModal && - } + {this.renderModals()} Maputnik - + Open {this.downloadButton()} - + Sources - + Style Settings - + Inspect diff --git a/src/components/modals/Modal.jsx b/src/components/modals/Modal.jsx index ccb6e1c..4d82b8a 100644 --- a/src/components/modals/Modal.jsx +++ b/src/components/modals/Modal.jsx @@ -31,7 +31,7 @@ class Modal extends React.Component { {this.props.title} this.props.onOpenToggle(false)} style={{ cursor: 'pointer' }} >