Move storing access token into style metadata

This commit is contained in:
Lukas Martinelli 2016-12-28 21:50:47 +01:00
parent 604be38b7c
commit ccc39b87db
3 changed files with 14 additions and 25 deletions

View file

@ -11,7 +11,7 @@ import Toolbar from './Toolbar'
import AppLayout from './AppLayout'
import style from '../libs/style.js'
import { loadDefaultStyle, SettingsStore, StyleStore } from '../libs/stylestore'
import { loadDefaultStyle, StyleStore } from '../libs/stylestore'
import { ApiStyleStore } from '../libs/apistore'
import { RevisionStore } from '../libs/revisions'
import LayerWatcher from '../libs/layerwatcher'
@ -31,9 +31,7 @@ export default class App extends React.Component {
this.styleStore.latestStyle(mapStyle => this.onStyleChanged(mapStyle))
})
this.settingsStore = new SettingsStore()
this.state = {
accessToken: this.settingsStore.accessToken,
mapStyle: style.emptyStyle,
selectedLayerIndex: 0,
}
@ -85,11 +83,6 @@ export default class App extends React.Component {
this.setState({ mapStyle: activeStyle })
}
onAccessTokenChanged(newToken) {
this.settingsStore.accessToken = newToken
this.setState({ accessToken: newToken })
}
onLayersChange(changedLayers) {
const changedStyle = {
...this.state.mapStyle,
@ -133,9 +126,10 @@ export default class App extends React.Component {
}
mapRenderer() {
const metadata = this.state.mapStyle.metadata || {}
const mapProps = {
mapStyle: this.state.mapStyle,
accessToken: this.state.accessToken,
accessToken: metadata['maputnik:access_token'],
onDataChange: (e) => {
this.layerWatcher.analyzeMap(e.map)
},
@ -146,7 +140,6 @@ export default class App extends React.Component {
}
}
const metadata = this.state.mapStyle.metadata || {}
const renderer = metadata['maputnik:renderer'] || 'mbgljs'
// Check if OL3 code has been loaded?

View file

@ -23,18 +23,19 @@ class SettingsModal extends React.Component {
this.props.onStyleChanged(changedStyle)
}
onRendererChange(renderer) {
onMetadataChange(key, value) {
const changedStyle = {
...this.props.mapStyle,
metadata: {
...this.props.mapStyle.metadata,
'maputnik:renderer': renderer,
[key]: value
}
}
this.props.onStyleChanged(changedStyle)
}
render() {
const metadata = this.props.mapStyle.metadata || {}
const inputProps = { }
return <Modal
isOpen={this.props.isOpen}
@ -67,6 +68,12 @@ class SettingsModal extends React.Component {
/>
</InputBlock>
<InputBlock label={"Access Token"}>
<StringInput {...inputProps}
value={metadata['maputnik:access_token']}
onChange={this.onMetadataChange.bind(this, "maputnik:access_token")}
/>
</InputBlock>
<InputBlock label={"Style Renderer"}>
<SelectInput {...inputProps}
@ -75,8 +82,8 @@ class SettingsModal extends React.Component {
['ol3', 'Open Layers 3'],
['inspection', 'Inspection Mode'],
]}
value={(this.props.mapStyle.metadata || {})['maputnik:renderer'] || 'mbgljs'}
onChange={this.onRendererChange.bind(this)}
value={metadata['maputnik:renderer'] || 'mbgljs'}
onChange={this.onMetadataChange.bind(this, 'maputnik:renderer')}
/>
</InputBlock>
</Modal>

View file

@ -61,17 +61,6 @@ function styleKey(styleId) {
return [storagePrefix, stylePrefix, styleId].join(":")
}
// Store style independent settings
export class SettingsStore {
get accessToken() {
const token = window.localStorage.getItem(storageKeys.accessToken)
return token ? token : ""
}
set accessToken(val) {
window.localStorage.setItem(storageKeys.accessToken, val)
}
}
// Manages many possible styles that are stored in the local storage
export class StyleStore {
// Tile store will load all items from local storage and