// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See License.txt for license information.
import $ from 'jquery';
import AtMentionProvider from './suggestion/at_mention_provider.jsx';
import ChannelMentionProvider from './suggestion/channel_mention_provider.jsx';
import CommandProvider from './suggestion/command_provider.jsx';
import EmoticonProvider from './suggestion/emoticon_provider.jsx';
import SuggestionList from './suggestion/suggestion_list.jsx';
import SuggestionBox from './suggestion/suggestion_box.jsx';
import ErrorStore from 'stores/error_store.jsx';
import * as TextFormatting from 'utils/text_formatting.jsx';
import * as Utils from 'utils/utils.jsx';
import Constants from 'utils/constants.jsx';
import {FormattedMessage} from 'react-intl';
const PreReleaseFeatures = Constants.PRE_RELEASE_FEATURES;
import PropTypes from 'prop-types';
import React from 'react';
export default class Textbox extends React.Component {
static propTypes = {
id: PropTypes.string.isRequired,
channelId: PropTypes.string,
value: PropTypes.string.isRequired,
onChange: PropTypes.func.isRequired,
onKeyPress: PropTypes.func.isRequired,
createMessage: PropTypes.string.isRequired,
previewMessageLink: PropTypes.string,
onKeyDown: PropTypes.func,
onBlur: PropTypes.func,
supportsCommands: PropTypes.bool.isRequired,
handlePostError: PropTypes.func,
suggestionListStyle: PropTypes.string,
emojiEnabled: PropTypes.bool,
isRHS: PropTypes.bool,
popoverMentionKeyClick: React.PropTypes.bool
};
static defaultProps = {
supportsCommands: true,
isRHS: false,
popoverMentionKeyClick: false
};
constructor(props) {
super(props);
this.state = {
connection: ''
};
this.suggestionProviders = [
new AtMentionProvider(this.props.channelId),
new ChannelMentionProvider(),
new EmoticonProvider()
];
if (props.supportsCommands) {
this.suggestionProviders.push(new CommandProvider());
}
}
componentDidMount() {
ErrorStore.addChangeListener(this.onReceivedError);
}
componentWillMount() {
this.checkMessageLength(this.props.value);
}
componentWillUnmount() {
ErrorStore.removeChangeListener(this.onReceivedError);
}
onReceivedError = () => {
const errorCount = ErrorStore.getConnectionErrorCount();
if (errorCount > 1) {
this.setState({connection: 'bad-connection'});
} else {
this.setState({connection: ''});
}
}
handleChange = (e) => {
this.checkMessageLength(e.target.value);
this.props.onChange(e);
}
checkMessageLength = (message) => {
if (this.props.handlePostError) {
if (message.length > Constants.CHARACTER_LIMIT) {
const errorMessage = (