diff --git a/components/ReadFileDropContainer.js b/components/ReadFileDropContainer.js index 1b72a9e..c635b38 100644 --- a/components/ReadFileDropContainer.js +++ b/components/ReadFileDropContainer.js @@ -1,28 +1,60 @@ -import React from 'react' -import { DropTarget } from 'react-dnd' -import { NativeTypes } from 'react-dnd-html5-backend' +const { createElement, Component } = require('react') +const { DropTarget } = require('react-dnd') +const { NativeTypes } = require('react-dnd-html5-backend') const spec = { - drop (props, monitor) { + drop(props, monitor, component) { const bundle = monitor.getItem() - const file = bundle.files[0] - const reader = new FileReader() - reader.onload = event => props.onDrop(event.target.result) - reader.readAsText(file, 'UTF-8'); + Promise.all( + bundle.files.map(file => { + const reader = new FileReader() + return new Promise((resolve, reject) => { + reader.onload = event => resolve(event.target.result) + reader.readAsText(file, 'UTF-8'); + }) + }) + ).then(contents => { + bundle.contents = contents + component.setState(state => ({ + lastContent: contents, + history: [bundle, ...state.history] + })) + props.onDrop(contents) + }) } } -const collect = (connect, monitor) => ({ connectDropTarget: connect.dropTarget(), isOver: monitor.isOver() }) +const collect = (connect, monitor) => ({ + connectDropTarget: connect.dropTarget(), + monitor, + isOver: monitor.isOver(), + canDrop: monitor.canDrop() +}) -const ReadFileDropContainer = props => props.connectDropTarget( -