Ignore gist endpoints less than 30 characters

main
Mike Fix 7 years ago committed by Michael Fix
parent 5b7d7833fc
commit 932f0ae225

@ -1,23 +1,21 @@
const { createElement, Component } = require('react') import { createElement, Component } from 'react'
const { DropTarget } = require('react-dnd') import { DropTarget } from 'react-dnd'
const { NativeTypes } = require('react-dnd-html5-backend') import { NativeTypes } from 'react-dnd-html5-backend'
const spec = { const spec = {
drop(props, monitor, component) { drop(props, monitor, component) {
const { files } = monitor.getItem() const { files } = monitor.getItem()
const reader = new FileReader()
Promise.all( Promise.all(
files files
.filter(props.filter || (i => i)) .filter(props.filter || (i => i))
.map(file => { .map(file => new Promise((resolve, reject) => {
const reader = new FileReader()
return new Promise((resolve, reject) => {
reader.onload = event => { reader.onload = event => {
file.content = event.target.result file.content = event.target.result
resolve(file) resolve(file)
} }
reader.readAsText(file, 'UTF-8'); reader.readAsText(file, 'UTF-8')
}) }))
})
).then(files => { ).then(files => {
component.setState(state => ({ component.setState(state => ({
lastContent: files, lastContent: files,
@ -54,11 +52,11 @@ class ReadFileDropContainer extends Component {
isOver: this.props.isOver, isOver: this.props.isOver,
canDrop: this.props.canDrop, canDrop: this.props.canDrop,
files: this.state.lastContent, files: this.state.lastContent,
history: this.state.history, history: this.state.history
}) })
) )
) )
} }
} }
module.exports = exports.default = DropTarget(NativeTypes.FILE, spec, collect)(ReadFileDropContainer) export default DropTarget(NativeTypes.FILE, spec, collect)(ReadFileDropContainer)

@ -27,8 +27,8 @@ class Editor extends React.Component {
/* pathname, asPath, err, req, res */ /* pathname, asPath, err, req, res */
static async getInitialProps ({ asPath }) { static async getInitialProps ({ asPath }) {
try { try {
// TODO make this check generic // TODO fix this hack
if (asPath && asPath !== '/' && asPath !== '/favicon.ico') { if (asPath.length > 30) {
const content = await api.getGist(asPath) const content = await api.getGist(asPath)
return { content } return { content }
} }

Loading…
Cancel
Save