|
|
@ -1,10 +1,11 @@ |
|
|
|
import CharacterCounter from './character_counter'; |
|
|
|
import CharacterCounter from './character_counter'; |
|
|
|
import Button from '../../../components/button'; |
|
|
|
import Button from '../../../components/button'; |
|
|
|
import PureRenderMixin from 'react-addons-pure-render-mixin'; |
|
|
|
import PureRenderMixin from 'react-addons-pure-render-mixin'; |
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes'; |
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes'; |
|
|
|
import ReplyIndicator from './reply_indicator'; |
|
|
|
import ReplyIndicator from './reply_indicator'; |
|
|
|
import UploadButton from './upload_button'; |
|
|
|
import UploadButton from './upload_button'; |
|
|
|
import Autosuggest from 'react-autosuggest'; |
|
|
|
import Autosuggest from 'react-autosuggest'; |
|
|
|
|
|
|
|
import AutosuggestAccountContainer from '../../compose/containers/autosuggest_account_container'; |
|
|
|
|
|
|
|
|
|
|
|
const getTokenForSuggestions = (str, caretPosition) => { |
|
|
|
const getTokenForSuggestions = (str, caretPosition) => { |
|
|
|
let word; |
|
|
|
let word; |
|
|
@ -31,11 +32,8 @@ const getTokenForSuggestions = (str, caretPosition) => { |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const getSuggestionValue = suggestion => suggestion.completion; |
|
|
|
const getSuggestionValue = suggestionId => suggestionId; |
|
|
|
|
|
|
|
const renderSuggestion = suggestionId => <AutosuggestAccountContainer id={suggestionId} />; |
|
|
|
const renderSuggestion = suggestion => ( |
|
|
|
|
|
|
|
<span>{suggestion.label}</span> |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const textareaStyle = { |
|
|
|
const textareaStyle = { |
|
|
|
display: 'block', |
|
|
|
display: 'block', |
|
|
@ -59,18 +57,26 @@ const ComposeForm = React.createClass({ |
|
|
|
|
|
|
|
|
|
|
|
propTypes: { |
|
|
|
propTypes: { |
|
|
|
text: React.PropTypes.string.isRequired, |
|
|
|
text: React.PropTypes.string.isRequired, |
|
|
|
|
|
|
|
suggestion_token: React.PropTypes.string, |
|
|
|
suggestions: React.PropTypes.array, |
|
|
|
suggestions: React.PropTypes.array, |
|
|
|
is_submitting: React.PropTypes.bool, |
|
|
|
is_submitting: React.PropTypes.bool, |
|
|
|
is_uploading: React.PropTypes.bool, |
|
|
|
is_uploading: React.PropTypes.bool, |
|
|
|
in_reply_to: ImmutablePropTypes.map, |
|
|
|
in_reply_to: ImmutablePropTypes.map, |
|
|
|
onChange: React.PropTypes.func.isRequired, |
|
|
|
onChange: React.PropTypes.func.isRequired, |
|
|
|
onSubmit: React.PropTypes.func.isRequired, |
|
|
|
onSubmit: React.PropTypes.func.isRequired, |
|
|
|
onCancelReply: React.PropTypes.func.isRequired |
|
|
|
onCancelReply: React.PropTypes.func.isRequired, |
|
|
|
|
|
|
|
onClearSuggestions: React.PropTypes.func.isRequired, |
|
|
|
|
|
|
|
onFetchSuggestions: React.PropTypes.func.isRequired, |
|
|
|
|
|
|
|
onSuggestionSelected: React.PropTypes.func.isRequired |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
mixins: [PureRenderMixin], |
|
|
|
mixins: [PureRenderMixin], |
|
|
|
|
|
|
|
|
|
|
|
handleChange (e) { |
|
|
|
handleChange (e) { |
|
|
|
|
|
|
|
if (typeof e.target.value === 'undefined' || typeof e.target.value === 'number') { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.props.onChange(e.target.value); |
|
|
|
this.props.onChange(e.target.value); |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
@ -86,8 +92,7 @@ const ComposeForm = React.createClass({ |
|
|
|
|
|
|
|
|
|
|
|
componentDidUpdate (prevProps) { |
|
|
|
componentDidUpdate (prevProps) { |
|
|
|
if (prevProps.text !== this.props.text || prevProps.in_reply_to !== this.props.in_reply_to) { |
|
|
|
if (prevProps.text !== this.props.text || prevProps.in_reply_to !== this.props.in_reply_to) { |
|
|
|
const node = ReactDOM.findDOMNode(this.refs.autosuggest); |
|
|
|
const textarea = this.autosuggest.input; |
|
|
|
const textarea = node.querySelector('textarea'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (textarea) { |
|
|
|
if (textarea) { |
|
|
|
textarea.focus(); |
|
|
|
textarea.focus(); |
|
|
@ -100,28 +105,31 @@ const ComposeForm = React.createClass({ |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
onSuggestionsFetchRequested ({ value }) { |
|
|
|
onSuggestionsFetchRequested ({ value }) { |
|
|
|
const node = ReactDOM.findDOMNode(this.refs.autosuggest); |
|
|
|
const textarea = this.autosuggest.input; |
|
|
|
const textarea = node.querySelector('textarea'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (textarea) { |
|
|
|
if (textarea) { |
|
|
|
const token = getTokenForSuggestions(value, textarea.selectionStart); |
|
|
|
const token = getTokenForSuggestions(value, textarea.selectionStart); |
|
|
|
|
|
|
|
|
|
|
|
if (token !== null) { |
|
|
|
if (token !== null) { |
|
|
|
this.props.onFetchSuggestions(token); |
|
|
|
this.props.onFetchSuggestions(token); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
this.props.onClearSuggestions(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
onSuggestionSelected (e, { suggestionValue, method }) { |
|
|
|
onSuggestionSelected (e, { suggestionValue }) { |
|
|
|
const node = ReactDOM.findDOMNode(this.refs.autosuggest); |
|
|
|
const textarea = this.autosuggest.input; |
|
|
|
const textarea = node.querySelector('textarea'); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (textarea) { |
|
|
|
if (textarea) { |
|
|
|
const str = this.props.text; |
|
|
|
this.props.onSuggestionSelected(textarea.selectionStart, suggestionValue); |
|
|
|
this.props.onChange([str.slice(0, textarea.selectionStart), suggestionValue, str.slice(textarea.selectionStart)].join('')); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}, |
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setRef (c) { |
|
|
|
|
|
|
|
this.autosuggest = c; |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
render () { |
|
|
|
render () { |
|
|
|
let replyArea = ''; |
|
|
|
let replyArea = ''; |
|
|
|
const disabled = this.props.is_submitting || this.props.is_uploading; |
|
|
|
const disabled = this.props.is_submitting || this.props.is_uploading; |
|
|
@ -143,8 +151,9 @@ const ComposeForm = React.createClass({ |
|
|
|
{replyArea} |
|
|
|
{replyArea} |
|
|
|
|
|
|
|
|
|
|
|
<Autosuggest |
|
|
|
<Autosuggest |
|
|
|
ref='autosuggest' |
|
|
|
ref={this.setRef} |
|
|
|
suggestions={this.props.suggestions} |
|
|
|
suggestions={this.props.suggestions} |
|
|
|
|
|
|
|
focusFirstSuggestion={true} |
|
|
|
onSuggestionsFetchRequested={this.onSuggestionsFetchRequested} |
|
|
|
onSuggestionsFetchRequested={this.onSuggestionsFetchRequested} |
|
|
|
onSuggestionsClearRequested={this.onSuggestionsClearRequested} |
|
|
|
onSuggestionsClearRequested={this.onSuggestionsClearRequested} |
|
|
|
onSuggestionSelected={this.onSuggestionSelected} |
|
|
|
onSuggestionSelected={this.onSuggestionSelected} |
|
|
|