Hook up imgur

main
Mike Fix 8 years ago
parent bb17e1ddbd
commit 01e8b46966

@ -87,7 +87,7 @@ const Toolbar = (props) => (
/> />
<Settings /> <Settings />
<Button <Button
onClick={props.copyLink} onClick={props.upload}
title="Copy Imgur Link" title="Copy Imgur Link"
bg="#84ACFC" bg="#84ACFC"
style={{ borderRadius: '3px 0px 0px 3px' }} style={{ borderRadius: '3px 0px 0px 3px' }}

@ -15,24 +15,17 @@ async function uploadImage (encodedImage) {
const data = new FormData() const data = new FormData()
data.append('image', encodedImage) data.append('image', encodedImage)
data.append('type', 'base64') data.append('type', 'image/png')
const config = { const config = {
headers: { headers: {
Authorization: ` Client-ID 87cc98dcdabcbb3` Authorization: `Client-ID 87cc98dcdabcbb3`
} }
} }
try { return axios.post(url, data, config)
const result = await axios.post(url, data, config) .then(res => res.data)
.catch(console.log)
console.log('success! ')
console.log(Object.keys(result.data))
console.log(result.data)
} catch (e) {
console.log('bummer man')
console.log(e)
}
} }
const getGist = (id) => { const getGist = (id) => {

@ -30,7 +30,6 @@ class Index extends React.Component {
} }
save () { save () {
// save
domtoimage.toJpeg(document.getElementById('container')) domtoimage.toJpeg(document.getElementById('container'))
.then((dataUrl) => { .then((dataUrl) => {
const link = document.createElement('a') const link = document.createElement('a')
@ -40,6 +39,13 @@ class Index extends React.Component {
}) })
} }
upload () {
domtoimage.toBlob(document.getElementById('container'))
.then(api.uploadImage)
.then(res => res.data.link)
.then(console.log)
}
render () { render () {
return ( return (
<div className="main"> <div className="main">
@ -48,6 +54,7 @@ class Index extends React.Component {
<div id="editor"> <div id="editor">
<Toolbar <Toolbar
save={this.save} save={this.save}
upload={this.upload}
onBGChange={color => this.setState({ bgColor: color })} onBGChange={color => this.setState({ bgColor: color })}
bg={this.state.bgColor} bg={this.state.bgColor}
/> />

Loading…
Cancel
Save