class UploadArea extends React.PureComponent {
+ constructor (props, context) {
+ super(props, context);
+
+ this.handleKeyUp = this.handleKeyUp.bind(this);
+ }
+
+ handleKeyUp (e) {
+ e.preventDefault();
+ e.stopPropagation();
+
+ const keyCode = e.keyCode
+ if (this.props.active) {
+ switch(keyCode) {
+ case 27:
+ this.props.onClose();
+ break;
+ }
+ }
+ }
+
+ componentDidMount () {
+ window.addEventListener('keyup', this.handleKeyUp, false);
+ }
+
+ componentWillUnmount () {
+ window.removeEventListener('keyup', this.handleKeyUp);
+ }
+
render () {
const { active } = this.props;
}
UploadArea.propTypes = {
- active: PropTypes.bool
+ active: PropTypes.bool,
+ onClose: PropTypes.func
};
export default UploadArea;
this.handleDragOver = this.handleDragOver.bind(this);
this.handleDrop = this.handleDrop.bind(this);
this.handleDragLeave = this.handleDragLeave.bind(this);
+ this.handleDragEnd = this.handleDragLeave.bind(this)
+ this.closeUploadModal = this.closeUploadModal.bind(this)
this.setRef = this.setRef.bind(this);
}
this.dragTargets.push(e.target);
}
- if (e.dataTransfer && e.dataTransfer.items.length > 0) {
+ if (e.dataTransfer && e.dataTransfer.types.includes('Files')) {
this.setState({ draggingOver: true });
}
}
this.setState({ draggingOver: false });
}
+ closeUploadModal() {
+ this.setState({ draggingOver: false });
+ }
+
componentWillMount () {
window.addEventListener('resize', this.handleResize, { passive: true });
document.addEventListener('dragenter', this.handleDragEnter, false);
document.addEventListener('dragover', this.handleDragOver, false);
document.addEventListener('drop', this.handleDrop, false);
document.addEventListener('dragleave', this.handleDragLeave, false);
+ document.addEventListener('dragend', this.handleDragEnd, false);
this.props.dispatch(refreshTimeline('home'));
this.props.dispatch(refreshNotifications());
document.removeEventListener('dragover', this.handleDragOver);
document.removeEventListener('drop', this.handleDrop);
document.removeEventListener('dragleave', this.handleDragLeave);
+ document.removeEventListener('dragend', this.handleDragEnd);
}
setRef (c) {
<NotificationsContainer />
<LoadingBarContainer className="loading-bar" />
<ModalContainer />
- <UploadArea active={draggingOver} />
+ <UploadArea active={draggingOver} onClose={this.closeUploadModal} />
</div>
);
}