Intial format request refactor

main
Mike Fix 7 years ago
parent acef413194
commit 5abef2b4c3

@ -105,7 +105,7 @@ class Editor extends React.Component {
saveState(localStorage, s) saveState(localStorage, s)
} }
getCarbonImage(format) { getCarbonImage({ format } = { format: 'png' }) {
const node = document.getElementById('export-container') const node = document.getElementById('export-container')
const config = { const config = {
@ -118,10 +118,9 @@ class Editor extends React.Component {
height: node.offsetHeight * 2 height: node.offsetHeight * 2
} }
if (format === 'svg') { return format.toLowerCase() === 'svg'
return domtoimage.toSvg(node, config) ? domtoimage.toSvg(node, config)
} : domtoimage.toPng(node, config)
return domtoimage.toPng(node, config)
} }
updateCode(code) { updateCode(code) {
@ -132,8 +131,8 @@ class Editor extends React.Component {
this.setState({ aspectRatio }) this.setState({ aspectRatio })
} }
save(format) { save({ format } = { format: 'png' }) {
this.getCarbonImage(format).then(dataUrl => { this.getCarbonImage({ format }).then(dataUrl => {
const link = document.createElement('a') const link = document.createElement('a')
link.download = 'carbon.' + format link.download = 'carbon.' + format
link.href = dataUrl link.href = dataUrl
@ -145,7 +144,7 @@ class Editor extends React.Component {
upload() { upload() {
this.setState({ uploading: true }) this.setState({ uploading: true })
this.getCarbonImage('png') this.getCarbonImage({ format: 'png' })
.then(api.tweet) .then(api.tweet)
.then(() => this.setState({ uploading: false })) .then(() => this.setState({ uploading: false }))
.catch(err => { .catch(err => {
@ -191,12 +190,16 @@ class Editor extends React.Component {
style={{ marginRight: '8px' }} style={{ marginRight: '8px' }}
/> />
<Button <Button
onClick={e => this.save('png')} onClick={e => this.save()}
title="Save Image (PNG)" title="Save Image (PNG)"
color="#c198fb" color="#c198fb"
style={{ marginRight: '8px' }} style={{ marginRight: '8px' }}
/> />
<Button onClick={e => this.save('svg')} title="Save Vector (SVG)" color="#9fca56" /> <Button
onClick={e => this.save({ format: 'svg' })}
title="Save Vector (SVG)"
color="#9fca56"
/>
</div> </div>
</Toolbar> </Toolbar>

Loading…
Cancel
Save