|
|
@ -1,7 +1,6 @@
|
|
|
|
import React from 'react'
|
|
|
|
import React from 'react'
|
|
|
|
import HTML5Backend from 'react-dnd-html5-backend'
|
|
|
|
import HTML5Backend from 'react-dnd-html5-backend'
|
|
|
|
import { DragDropContext } from 'react-dnd'
|
|
|
|
import { DragDropContext } from 'react-dnd'
|
|
|
|
import Axios from 'axios'
|
|
|
|
|
|
|
|
import domtoimage from 'dom-to-image'
|
|
|
|
import domtoimage from 'dom-to-image'
|
|
|
|
|
|
|
|
|
|
|
|
import Page from '../components/Page'
|
|
|
|
import Page from '../components/Page'
|
|
|
@ -34,11 +33,15 @@ class Editor extends React.Component {
|
|
|
|
dropShadow: true,
|
|
|
|
dropShadow: true,
|
|
|
|
windowControls: true,
|
|
|
|
windowControls: true,
|
|
|
|
paddingVertical: '48px',
|
|
|
|
paddingVertical: '48px',
|
|
|
|
paddingHorizontal: '32px'
|
|
|
|
paddingHorizontal: '32px',
|
|
|
|
|
|
|
|
uploading: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.save = this.save.bind(this)
|
|
|
|
|
|
|
|
this.upload = this.upload.bind(this)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
save () {
|
|
|
|
getCarbonImage () {
|
|
|
|
const node = document.getElementById('section')
|
|
|
|
const node = document.getElementById('section')
|
|
|
|
|
|
|
|
|
|
|
|
const config = {
|
|
|
|
const config = {
|
|
|
@ -50,7 +53,11 @@ class Editor extends React.Component {
|
|
|
|
height: node.offsetHeight * 2
|
|
|
|
height: node.offsetHeight * 2
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
domtoimage.toPng(node, config)
|
|
|
|
return domtoimage.toPng(node, config)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
save () {
|
|
|
|
|
|
|
|
this.getCarbonImage()
|
|
|
|
.then((dataUrl) => {
|
|
|
|
.then((dataUrl) => {
|
|
|
|
const link = document.createElement('a')
|
|
|
|
const link = document.createElement('a')
|
|
|
|
link.download = 'snippet.png'
|
|
|
|
link.download = 'snippet.png'
|
|
|
@ -60,30 +67,27 @@ class Editor extends React.Component {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
upload () {
|
|
|
|
upload () {
|
|
|
|
domtoimage.toBlob(document.getElementById('container'))
|
|
|
|
this.setState({ uploading: true })
|
|
|
|
.then(api.uploadImage)
|
|
|
|
this.getCarbonImage()
|
|
|
|
.then(res => res.data.id)
|
|
|
|
.then(api.tweet)
|
|
|
|
.then(id => `http://i.imgur.com/${id}`)
|
|
|
|
.then(() => this.setState({ uploading: false }))
|
|
|
|
.then(console.log)
|
|
|
|
.catch(console.error)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
render () {
|
|
|
|
render () {
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<Page enableHeroText>
|
|
|
|
<Page enableHeroText>
|
|
|
|
{/* TODO this doesn't update the render */}
|
|
|
|
|
|
|
|
<ReadFileDropContainer
|
|
|
|
<ReadFileDropContainer
|
|
|
|
onDrop={(droppedContent) => {
|
|
|
|
onDrop={droppedContent => this.setState({ droppedContent })}
|
|
|
|
console.log(droppedContent)
|
|
|
|
|
|
|
|
this.setState({ droppedContent })
|
|
|
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
>
|
|
|
|
>
|
|
|
|
<div id="editor">
|
|
|
|
<div id="editor">
|
|
|
|
<Toolbar
|
|
|
|
<Toolbar
|
|
|
|
save={this.save}
|
|
|
|
save={this.save}
|
|
|
|
upload={this.upload}
|
|
|
|
upload={this.upload}
|
|
|
|
|
|
|
|
uploading={this.state.uploading}
|
|
|
|
onBGChange={color => this.setState({ background: color })}
|
|
|
|
onBGChange={color => this.setState({ background: color })}
|
|
|
|
onThemeChange={theme => this.setState({ theme: theme.id })}
|
|
|
|
onThemeChange={theme => this.setState({ theme: theme.id })}
|
|
|
|
onLanguageChange={language => this.setState({ language })}
|
|
|
|
onLanguageChange={language => this.setState({ language: language.module })}
|
|
|
|
onSettingsChange={(key, value) => this.setState({ [key]: value })}
|
|
|
|
onSettingsChange={(key, value) => this.setState({ [key]: value })}
|
|
|
|
bg={this.state.background}
|
|
|
|
bg={this.state.background}
|
|
|
|
enabled={this.state}
|
|
|
|
enabled={this.state}
|
|
|
|