diff options
-rw-r--r-- | web/react/components/create_comment.jsx | 14 | ||||
-rw-r--r-- | web/react/components/create_post.jsx | 15 | ||||
-rw-r--r-- | web/react/utils/constants.jsx | 3 | ||||
-rw-r--r-- | web/react/utils/text_formatting.jsx | 8 |
4 files changed, 30 insertions, 10 deletions
diff --git a/web/react/components/create_comment.jsx b/web/react/components/create_comment.jsx index 9e7c67515..709485991 100644 --- a/web/react/components/create_comment.jsx +++ b/web/react/components/create_comment.jsx @@ -59,6 +59,7 @@ class CreateComment extends React.Component { this.getFileCount = this.getFileCount.bind(this); this.handleResize = this.handleResize.bind(this); this.onPreferenceChange = this.onPreferenceChange.bind(this); + this.focusTextbox = this.focusTextbox.bind(this); PostStore.clearCommentDraftUploads(); @@ -76,7 +77,7 @@ class CreateComment extends React.Component { PreferenceStore.addChangeListener(this.onPreferenceChange); window.addEventListener('resize', this.handleResize); - this.refs.textbox.focus(); + this.focusTextbox(); } componentWillUnmount() { PreferenceStore.removeChangeListener(this.onPreferenceChange); @@ -99,7 +100,7 @@ class CreateComment extends React.Component { } if (prevProps.rootId !== this.props.rootId) { - this.refs.textbox.focus(); + this.focusTextbox(); } } handleSubmit(e) { @@ -226,7 +227,7 @@ class CreateComment extends React.Component { } } handleUploadClick() { - this.refs.textbox.focus(); + this.focusTextbox(); } handleUploadStart(clientIds) { let draft = PostStore.getCommentDraft(this.props.rootId); @@ -238,7 +239,7 @@ class CreateComment extends React.Component { // this is a bit redundant with the code that sets focus when the file input is clicked, // but this also resets the focus after a drag and drop - this.refs.textbox.focus(); + this.focusTextbox(); } handleFileUploadComplete(filenames, clientIds) { let draft = PostStore.getCommentDraft(this.props.rootId); @@ -306,6 +307,11 @@ class CreateComment extends React.Component { getFileCount() { return this.state.previews.length + this.state.uploadsInProgress.length; } + focusTextbox() { + if (!Utils.isMobile()) { + this.refs.textbox.focus(); + } + } render() { let serverError = null; if (this.state.serverError) { diff --git a/web/react/components/create_post.jsx b/web/react/components/create_post.jsx index 6ea80cd13..ecabdaee6 100644 --- a/web/react/components/create_post.jsx +++ b/web/react/components/create_post.jsx @@ -63,6 +63,7 @@ class CreatePost extends React.Component { this.getFileCount = this.getFileCount.bind(this); this.handleKeyDown = this.handleKeyDown.bind(this); this.sendMessage = this.sendMessage.bind(this); + this.focusTextbox = this.focusTextbox.bind(this); PostStore.clearDraftUploads(); @@ -193,6 +194,11 @@ class CreatePost extends React.Component { } ); } + focusTextbox() { + if (!Utils.isMobile()) { + this.refs.textbox.focus(); + } + } postMsgKeyPress(e) { if (this.state.ctrlSend && e.ctrlKey || !this.state.ctrlSend) { if (e.which === KeyCodes.ENTER && !e.shiftKey && !e.altKey) { @@ -216,7 +222,7 @@ class CreatePost extends React.Component { PostStore.storeCurrentDraft(draft); } handleUploadClick() { - this.refs.textbox.focus(); + this.focusTextbox(); } handleUploadStart(clientIds, channelId) { const draft = PostStore.getDraft(channelId); @@ -228,7 +234,7 @@ class CreatePost extends React.Component { // this is a bit redundant with the code that sets focus when the file input is clicked, // but this also resets the focus after a drag and drop - this.refs.textbox.focus(); + this.focusTextbox(); } handleFileUploadComplete(filenames, clientIds, channelId) { const draft = PostStore.getDraft(channelId); @@ -305,11 +311,12 @@ class CreatePost extends React.Component { componentDidMount() { ChannelStore.addChangeListener(this.onChange); PreferenceStore.addChangeListener(this.onPreferenceChange); - this.refs.textbox.focus(); + + this.focusTextbox(); } componentDidUpdate(prevProps, prevState) { if (prevState.channelId !== this.state.channelId) { - this.refs.textbox.focus(); + this.focusTextbox(); } } componentWillUnmount() { diff --git a/web/react/utils/constants.jsx b/web/react/utils/constants.jsx index 64d4ea8a1..d78776aa3 100644 --- a/web/react/utils/constants.jsx +++ b/web/react/utils/constants.jsx @@ -467,5 +467,6 @@ export default { MAX_USERNAME_LENGTH: 64, MIN_PASSWORD_LENGTH: 5, MAX_PASSWORD_LENGTH: 50, - TIME_SINCE_UPDATE_INTERVAL: 30000 + TIME_SINCE_UPDATE_INTERVAL: 30000, + MIN_HASHTAG_LINK_LENGTH: 3 }; diff --git a/web/react/utils/text_formatting.jsx b/web/react/utils/text_formatting.jsx index e837ded53..dae2252a6 100644 --- a/web/react/utils/text_formatting.jsx +++ b/web/react/utils/text_formatting.jsx @@ -248,8 +248,14 @@ function autolinkHashtags(text, tokens) { const index = tokens.size; const alias = `MM_HASHTAG${index}`; + let value = hashtag; + + if (hashtag.length > Constants.MIN_HASHTAG_LINK_LENGTH) { + value = `<a class='mention-link' href='#' data-hashtag='${hashtag}'>${hashtag}</a>`; + } + tokens.set(alias, { - value: `<a class='mention-link' href='#' data-hashtag='${hashtag}'>${hashtag}</a>`, + value, originalText: hashtag }); |