mirror of https://github.com/sgoudham/carbon.git
Clean up old code
parent
2f0f7f80ef
commit
646d8919c5
@ -1,93 +0,0 @@
|
||||
import React from 'react'
|
||||
import domtoimage from 'dom-to-image'
|
||||
|
||||
import Button from './Button'
|
||||
import api from '../lib/api'
|
||||
|
||||
// constants
|
||||
const BUTTON_COLOR = '#c198fb'
|
||||
const BUTTON_STYLE = { marginRight: '8px' }
|
||||
const DEBOUNCE_DURATION = 10000
|
||||
|
||||
const STATUS = {
|
||||
IDLE: 'IDLE',
|
||||
LOADING: 'LOADING',
|
||||
DEBOUNCED: 'DEBOUNCED'
|
||||
}
|
||||
|
||||
const textMap = {
|
||||
[STATUS.IDLE]: 'Copy Imgur Link',
|
||||
[STATUS.LOADING]: 'Uploading...',
|
||||
[STATUS.DEBOUNCED]: 'Copied to Clipboard'
|
||||
}
|
||||
|
||||
class CopyButton extends React.Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
this.state = {
|
||||
status: STATUS.IDLE
|
||||
}
|
||||
|
||||
// bind methods
|
||||
this.handleIdleClick = this.handleIdleClick.bind(this)
|
||||
this.handleDebounceClick = this.handleDebounceClick.bind(this)
|
||||
this.handleClick = this.handleClick.bind(this)
|
||||
}
|
||||
|
||||
uploadImage () {
|
||||
return domtoimage.toBlob(document.getElementById('container'))
|
||||
.then(api.uploadImage)
|
||||
.then(res => res.data.id)
|
||||
.then(id => `http://i.imgur.com/${id}`)
|
||||
}
|
||||
|
||||
handleIdleClick () {
|
||||
// set to loading
|
||||
this.setState({
|
||||
status: STATUS.LOADING
|
||||
})
|
||||
|
||||
// upload code image and update state
|
||||
this.uploadImage()
|
||||
.then(link => {
|
||||
console.log('link')
|
||||
this.setState({
|
||||
status: STATUS.DEBOUNCED,
|
||||
link
|
||||
})
|
||||
|
||||
setTimeout(() => {
|
||||
this.setState({
|
||||
status: STATUS.IDLE
|
||||
})
|
||||
}, DEBOUNCE_DURATION)
|
||||
})
|
||||
}
|
||||
|
||||
handleDebounceClick () {
|
||||
// copy link to clipboard
|
||||
}
|
||||
|
||||
handleClick () {
|
||||
console.log('called!')
|
||||
switch (this.state.status) {
|
||||
case STATUS.IDLE:
|
||||
this.handleIdleClick()
|
||||
break
|
||||
case STATUS.DEBOUNCED:
|
||||
this.handleDebounceClick()
|
||||
}
|
||||
}
|
||||
|
||||
render () {
|
||||
return (
|
||||
<div >
|
||||
{ this.state.link ? <input id="linkTarget" type="hidden" value="https://github.com/zenorocha/clipboard.js.git" /> : null }
|
||||
<Button onClick={this.handleClick} title={textMap[this.state.status]} color={BUTTON_COLOR} style={BUTTON_STYLE} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export default CopyButton
|
@ -1,25 +0,0 @@
|
||||
const drop = (props, monitor, component) => {
|
||||
const bundle = monitor.getItem()
|
||||
const file = bundle.files[0]
|
||||
const reader = new FileReader()
|
||||
reader.onload = function(event) {
|
||||
component.setState({
|
||||
droppedContent: event.target.result
|
||||
})
|
||||
};
|
||||
reader.readAsText(file, "UTF-8");
|
||||
}
|
||||
|
||||
export default DropTarget(NativeTypes.FILE, { drop }, (connect, monitor) => ({
|
||||
connectDropTarget: connect.dropTarget(),
|
||||
isOver: monitor.isOver(),
|
||||
canDrop: monitor.canDrop(),
|
||||
item: monitor.getItem()
|
||||
}))(Carbon)
|
||||
|
||||
|
||||
let code = this.props.content
|
||||
const split = code.split(EOL)
|
||||
if (split.length > MAX_LINES) code = [...split.slice(0, MAX_LINES - 1), '', '...'].join(EOL)
|
||||
|
||||
return this.props.connectDropTarget(
|
@ -1,43 +0,0 @@
|
||||
const FormData = require('form-data')
|
||||
const axios = require('axios')
|
||||
|
||||
module.exports = async (req, res) => {
|
||||
// validate input
|
||||
if (!req.body.image || typeof req.body.image !== 'string') {
|
||||
const error = {
|
||||
code: 1,
|
||||
title: 'no image provided',
|
||||
detail: '\'image\' key must be set to a base64 encoded image'
|
||||
}
|
||||
res.status(400).json({ errors: [error] })
|
||||
}
|
||||
|
||||
const image = req.body.image
|
||||
|
||||
// upload image
|
||||
const url = 'https://api.imgur.com/3/image'
|
||||
|
||||
const data = new FormData()
|
||||
data.append('image', image)
|
||||
data.append('type', 'base64')
|
||||
|
||||
const config = {
|
||||
headers: {
|
||||
Authorization: ` Client-ID ${process.env.IMGUR_ID}`
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await axios.post(url, data, config)
|
||||
|
||||
if (!result.link) {
|
||||
throw new Error('imgur failed to provide a link')
|
||||
}
|
||||
|
||||
res.status(200).json({ data: { link: result.link } })
|
||||
} catch (e) {
|
||||
console.log(Object.keys(e.response))
|
||||
const error = { code: 2, title: 'error uploading to imgur' }
|
||||
res.status(500).json({ errors: [error] })
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue