Clean up old code

main
Mike Fix 7 years ago committed by Jake Dexheimer
parent 2f0f7f80ef
commit 646d8919c5

@ -10,7 +10,7 @@ Visit [dawnlabs.io/carbon](http://dawnlabs.io/carbon) or read [our post](TODO) t
* **Import from GitHub gist**. Simply append a GitHub gist id to the url
* **Customization**. Customize things like your image's syntax theme, window style, and more
* **Share quickly**. Save your image or copy a Imgur link to it with one click
* **Share quickly**. Save your image or Tweet a link with one click
## Usage
@ -27,7 +27,7 @@ Once you've got all of your code into Carbon, you can customize your image by ch
#### Export/Sharing
After you've customized your image you can copy an Imgur link to the image, or save it directly.
After you've customized your image you can either Tweet a link to the image, or save it directly.
## Contribute

@ -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

@ -3,7 +3,6 @@ import Dropdown from './Dropdown'
import ColorPicker from './ColorPicker'
import Settings from './Settings'
import Button from './Button'
import CopyButton from './CopyButton'
import { THEMES, LANGUAGES } from '../lib/constants'
const Toolbar = (props) => (

@ -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] })
}
}

@ -21,25 +21,6 @@ async function tweet (encodedImage) {
.then(openTwitterUrl)
}
async function uploadImage (encodedImage) {
// upload image
const url = 'https://api.imgur.com/3/image'
const data = new FormData()
data.append('image', encodedImage)
data.append('type', 'image/png')
const config = {
headers: {
Authorization: `Client-ID 87cc98dcdabcbb3`
}
}
return axios.post(url, data, config)
.then(res => res.data)
.catch(console.log)
}
const getGist = (id) => {
const uid = id.split('/').pop()
return gistClient.get(`/gists/${uid}`)
@ -49,13 +30,6 @@ const getGist = (id) => {
.then(file => file.content)
}
export default {
uploadImage,
getGist,
tweet
}
// private
function openTwitterUrl (twitterUrl) {
const width = 575, height = 400
@ -65,3 +39,9 @@ function openTwitterUrl (twitterUrl) {
window.open(twitterUrl, 'twitter', opts)
}
export default {
getGist,
tweet
}

@ -23,7 +23,7 @@ export default () => (
<h4 className="mb0">Customization</h4>
<p className="mt2 mb3">Once you've got all of your code into Carbon, you can customize your image by changing the syntax theme, background color, window theme, or padding.</p>
<h4 className="mb0">Export/Sharing</h4>
<p className="mt2">After you've customized your image you can copy an Imgur link to the image, or save it directly.</p>
<p className="mt2">After you've customized your image you can Tweet a link to the image, or save it directly.</p>
</div>
<div>
<h2>I want to make this better.</h2>

@ -31,7 +31,6 @@ app.prepare()
server.get('*', handle)
// api endpoints
server.post('/upload', bodyParser.json(), wrap(require('./handlers/upload')))
server.post('/twitter', bodyParser.json({ limit: '5mb' }), require('./handlers/twitter'))
server.listen(port, (err) => {

Loading…
Cancel
Save