value: React.PropTypes.string,
suggestions: ImmutablePropTypes.list,
disabled: React.PropTypes.bool,
+ fileDropDate: React.PropTypes.instanceOf(Date),
placeholder: React.PropTypes.string,
onSuggestionSelected: React.PropTypes.func.isRequired,
onSuggestionsClearRequested: React.PropTypes.func.isRequired,
getInitialState () {
return {
+ isFileDragging: false,
+ fileDraggingDate: undefined,
suggestionsHidden: false,
selectedSuggestion: 0,
lastToken: null,
if (nextProps.suggestions !== this.props.suggestions && nextProps.suggestions.size > 0 && this.state.suggestionsHidden) {
this.setState({ suggestionsHidden: false });
}
+
+ const fileDropDate = nextProps.fileDropDate;
+ const { isFileDragging, fileDraggingDate } = this.state;
+
+ /*
+ * We can't detect drop events, because they might not be on the textarea (the app allows dropping anywhere in the
+ * window). Instead, on-drop, we notify this textarea to stop its hover effect by passing in a prop with the
+ * drop-date.
+ */
+ if (isFileDragging && fileDraggingDate && fileDropDate // if dragging when props updated, and dates aren't undefined
+ && fileDropDate > fileDraggingDate) { // and if the drop date is now greater than when we started dragging
+ // then we should stop dragging
+ this.setState({
+ isFileDragging: false
+ });
+ }
},
setTextarea (c) {
this.textarea = c;
},
+ onDragEnter () {
+ this.setState({
+ isFileDragging: true,
+ fileDraggingDate: new Date()
+ })
+ },
+
+ onDragExit () {
+ this.setState({
+ isFileDragging: false
+ })
+ },
+
render () {
- const { value, suggestions, disabled, placeholder, onKeyUp } = this.props;
- const { suggestionsHidden, selectedSuggestion } = this.state;
+ const { value, suggestions, fileDropDate, disabled, placeholder, onKeyUp } = this.props;
+ const { isFileDragging, suggestionsHidden, selectedSuggestion } = this.state;
+ const className = isFileDragging ? 'autosuggest-textarea__textarea file-drop' : 'autosuggest-textarea__textarea';
return (
<div className='autosuggest-textarea'>
<textarea
ref={this.setTextarea}
- className='autosuggest-textarea__textarea'
+ className={className}
disabled={disabled}
placeholder={placeholder}
value={value}
onKeyDown={this.onKeyDown}
onKeyUp={onKeyUp}
onBlur={this.onBlur}
+ onDragEnter={this.onDragEnter}
+ onDragExit={this.onDragExit}
/>
<div style={{ display: (suggestions.size > 0 && !suggestionsHidden) ? 'block' : 'none' }} className='autosuggest-textarea__suggestions'>
sensitive: React.PropTypes.bool,
unlisted: React.PropTypes.bool,
private: React.PropTypes.bool,
+ fileDropDate: React.PropTypes.instanceOf(Date),
is_submitting: React.PropTypes.bool,
is_uploading: React.PropTypes.bool,
in_reply_to: ImmutablePropTypes.map,
ref={this.setAutosuggestTextarea}
placeholder={intl.formatMessage(messages.placeholder)}
disabled={disabled}
+ fileDropDate={this.props.fileDropDate}
value={this.props.text}
onChange={this.handleChange}
suggestions={this.props.suggestions}
sensitive: state.getIn(['compose', 'sensitive']),
unlisted: state.getIn(['compose', 'unlisted']),
private: state.getIn(['compose', 'private']),
+ fileDropDate: state.getIn(['compose', 'fileDropDate']),
is_submitting: state.getIn(['compose', 'is_submitting']),
is_uploading: state.getIn(['compose', 'is_uploading']),
in_reply_to: getStatus(state, state.getIn(['compose', 'in_reply_to'])),
unlisted: false,
private: false,
text: '',
+ fileDropDate: null,
in_reply_to: null,
is_submitting: false,
is_uploading: false,
case COMPOSE_SUBMIT_FAIL:
return state.set('is_submitting', false);
case COMPOSE_UPLOAD_REQUEST:
- return state.set('is_uploading', true);
+ return state.withMutations(map => {
+ map.set('is_uploading', true);
+ map.set('fileDropDate', new Date());
+ });
case COMPOSE_UPLOAD_SUCCESS:
return appendMedia(state, Immutable.fromJS(action.media));
case COMPOSE_UPLOAD_FAIL: