update pages/components to handle new tweet functionality

main
briandennis 7 years ago
parent 3a60e4622f
commit fd38138dae

@ -16,7 +16,7 @@ const Toolbar = (props) => (
/> />
<Settings onChange={props.onSettingsChange} enabled={props.enabled} /> <Settings onChange={props.onSettingsChange} enabled={props.enabled} />
<div className="buttons"> <div className="buttons">
<CopyButton /> <Button className="tweetButton" onClick={props.upload} title={props.uploading ? 'loading...' : 'Tweet Image'} color="#0084b4" style={{ marginRight: '8px' }} />
<Button onClick={props.save} title="Save Image" color="#57b5f9" /> <Button onClick={props.save} title="Save Image" color="#57b5f9" />
</div> </div>
<style jsx>{` <style jsx>{`

@ -17,7 +17,7 @@ export default () => (
<p className="mb1 mt2">There are a few different ways to import code into Carbon:</p> <p className="mb1 mt2">There are a few different ways to import code into Carbon:</p>
<ul className="mt0 mb3"> <ul className="mt0 mb3">
<li>Drag a file into the editor</li> <li>Drag a file into the editor</li>
<li>Append a GitHub gist id to the url (<a className="link" href="#">example</a>)</li> <li>Append a GitHub gist id to the url (<a className="link" href="/0db00e81d5416c339181e59481c74b59">example</a>)</li>
<li>Paste your code directly</li> <li>Paste your code directly</li>
</ul> </ul>
<h4 className="mb0">Customization</h4> <h4 className="mb0">Customization</h4>

@ -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,40 +53,41 @@ class Editor extends React.Component {
height: node.offsetHeight * 2 height: node.offsetHeight * 2
} }
domtoimage.toPng(node, config) return domtoimage.toPng(node, config)
.then((dataUrl) => { }
const link = document.createElement('a')
link.download = 'snippet.png' save () {
link.href = dataUrl this.getCarbonImage()
link.click() .then((dataUrl) => {
}) const link = document.createElement('a')
link.download = 'snippet.png'
link.href = dataUrl
link.click()
})
} }
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}

Loading…
Cancel
Save