Update sources if they change

This commit is contained in:
Lukas Martinelli
2016-12-29 15:22:47 +01:00
parent bf5131cadd
commit 29cfb58a56
7 changed files with 46 additions and 13 deletions

View File

@@ -24,16 +24,26 @@ class AddModal extends React.Component {
constructor(props) {
super(props)
console.log('sources', this.props.sources)
this.state = {
type: 'fill',
id: '',
//source: Object.keys(this.props.sources)[0],
//'source-layer': this.props.sources[0][0]
}
if(props.sources.length > 0) {
this.state.source = Object.keys(this.props.sources)[0]
}
}
componentWillReceiveProps(nextProps) {
const sourceIds = Object.keys(nextProps.sources)
if(!this.state.source && sourceIds.length > 0) {
this.setState({
source: sourceIds[0],
})
}
}
render() {
return <Modal
isOpen={this.props.isOpen}