fix render bug

main
briandennis 7 years ago
parent 52fcb7e86b
commit d8f2735437

@ -23,10 +23,11 @@ class Carbon extends React.Component {
this.state = {
loading: true,
language: props.config.language
language: props.config.language,
}
this.handleLanguageChange = this.handleLanguageChange.bind(this)
this.codeUpdated = this.codeUpdated.bind(this)
}
componentDidMount() {
@ -41,6 +42,11 @@ class Carbon extends React.Component {
this.handleLanguageChange(newProps.children, { customProps: newProps })
}
codeUpdated (newCode) {
this.handleLanguageChange(newCode)
this.props.updateCode(newCode)
}
handleLanguageChange(newCode, config) {
const props = (config && config.customProps) || this.props
@ -93,7 +99,7 @@ class Carbon extends React.Component {
{ config.windowControls ? <WindowControls theme={config.windowTheme} /> : null }
<CodeMirror
className={`CodeMirror__container window-theme__${config.windowTheme} ${config.dropShadow ? 'dropshadow' : ''}`}
onChange={this.handleLanguageChange}
onChange={this.codeUpdated}
value={this.props.children}
options={options}
/>

@ -34,11 +34,13 @@ class Editor extends React.Component {
windowControls: true,
paddingVertical: '48px',
paddingHorizontal: '32px',
uploading: false
uploading: false,
code: DEFAULT_CODE
}
this.save = this.save.bind(this)
this.upload = this.upload.bind(this)
this.updateCode = this.updateCode.bind(this)
}
getCarbonImage () {
@ -56,6 +58,10 @@ class Editor extends React.Component {
return domtoimage.toPng(node, config)
}
updateCode (code) {
this.setState({ code })
}
save () {
this.getCarbonImage()
.then((dataUrl) => {
@ -95,8 +101,8 @@ class Editor extends React.Component {
bg={this.state.background}
enabled={this.state}
/>
<Carbon config={this.state}>
{this.state.droppedContent || this.props.content || DEFAULT_CODE}
<Carbon config={this.state} updateCode={this.updateCode}>
{this.state.droppedContent || this.props.content || this.state.code}
</Carbon>
</div>
</ReadFileDropContainer>

Loading…
Cancel
Save