|
|
@ -1,23 +1,19 @@
|
|
|
|
import React from 'react';
|
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
|
|
import ImmutablePropTypes from 'react-immutable-proptypes';
|
|
|
|
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
|
|
|
import ReplyIndicatorContainer from '../containers/reply_indicator_container';
|
|
|
|
|
|
|
|
import AutosuggestTextarea from '../../../components/autosuggest_textarea';
|
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
|
|
|
import { defineMessages, injectIntl } from 'react-intl';
|
|
|
|
|
|
|
|
import EmojiPicker from 'flavours/glitch/features/emoji_picker';
|
|
|
|
|
|
|
|
import PollFormContainer from '../containers/poll_form_container';
|
|
|
|
|
|
|
|
import UploadFormContainer from '../containers/upload_form_container';
|
|
|
|
|
|
|
|
import WarningContainer from '../containers/warning_container';
|
|
|
|
|
|
|
|
import { isMobile } from 'flavours/glitch/util/is_mobile';
|
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
|
|
|
import ImmutablePureComponent from 'react-immutable-pure-component';
|
|
|
|
|
|
|
|
import { countableText } from 'flavours/glitch/util/counter';
|
|
|
|
// Components.
|
|
|
|
|
|
|
|
import OptionsContainer from '../containers/options_container';
|
|
|
|
import OptionsContainer from '../containers/options_container';
|
|
|
|
import Publisher from './publisher';
|
|
|
|
import Publisher from './publisher';
|
|
|
|
import TextareaIcons from './textarea_icons';
|
|
|
|
import TextareaIcons from './textarea_icons';
|
|
|
|
import UploadFormContainer from '../containers/upload_form_container';
|
|
|
|
|
|
|
|
import PollFormContainer from '../containers/poll_form_container';
|
|
|
|
|
|
|
|
import WarningContainer from '../containers/warning_container';
|
|
|
|
|
|
|
|
import ReplyIndicatorContainer from '../containers/reply_indicator_container';
|
|
|
|
|
|
|
|
import EmojiPicker from 'flavours/glitch/features/emoji_picker';
|
|
|
|
|
|
|
|
import AutosuggestTextarea from '../../../components/autosuggest_textarea';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Utils.
|
|
|
|
|
|
|
|
import { countableText } from 'flavours/glitch/util/counter';
|
|
|
|
|
|
|
|
import { isMobile } from 'flavours/glitch/util/is_mobile';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const messages = defineMessages({
|
|
|
|
const messages = defineMessages({
|
|
|
|
placeholder: { id: 'compose_form.placeholder', defaultMessage: 'What is on your mind?' },
|
|
|
|
placeholder: { id: 'compose_form.placeholder', defaultMessage: 'What is on your mind?' },
|
|
|
@ -37,84 +33,50 @@ class ComposeForm extends ImmutablePureComponent {
|
|
|
|
|
|
|
|
|
|
|
|
static propTypes = {
|
|
|
|
static propTypes = {
|
|
|
|
intl: PropTypes.object.isRequired,
|
|
|
|
intl: PropTypes.object.isRequired,
|
|
|
|
|
|
|
|
text: PropTypes.string,
|
|
|
|
// State props.
|
|
|
|
suggestions: ImmutablePropTypes.list,
|
|
|
|
advancedOptions: ImmutablePropTypes.map,
|
|
|
|
spoiler: PropTypes.bool,
|
|
|
|
amUnlocked: PropTypes.bool,
|
|
|
|
privacy: PropTypes.string,
|
|
|
|
|
|
|
|
spoilerText: PropTypes.string,
|
|
|
|
focusDate: PropTypes.instanceOf(Date),
|
|
|
|
focusDate: PropTypes.instanceOf(Date),
|
|
|
|
caretPosition: PropTypes.number,
|
|
|
|
caretPosition: PropTypes.number,
|
|
|
|
|
|
|
|
preselectDate: PropTypes.instanceOf(Date),
|
|
|
|
isSubmitting: PropTypes.bool,
|
|
|
|
isSubmitting: PropTypes.bool,
|
|
|
|
isChangingUpload: PropTypes.bool,
|
|
|
|
isChangingUpload: PropTypes.bool,
|
|
|
|
isUploading: PropTypes.bool,
|
|
|
|
isUploading: PropTypes.bool,
|
|
|
|
|
|
|
|
onChange: PropTypes.func,
|
|
|
|
|
|
|
|
onSubmit: PropTypes.func,
|
|
|
|
|
|
|
|
onClearSuggestions: PropTypes.func,
|
|
|
|
|
|
|
|
onFetchSuggestions: PropTypes.func,
|
|
|
|
|
|
|
|
onSuggestionSelected: PropTypes.func,
|
|
|
|
|
|
|
|
onChangeSpoilerText: PropTypes.func,
|
|
|
|
|
|
|
|
onPaste: PropTypes.func,
|
|
|
|
|
|
|
|
onPickEmoji: PropTypes.func,
|
|
|
|
|
|
|
|
showSearch: PropTypes.bool,
|
|
|
|
|
|
|
|
anyMedia: PropTypes.bool,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
advancedOptions: ImmutablePropTypes.map,
|
|
|
|
layout: PropTypes.string,
|
|
|
|
layout: PropTypes.string,
|
|
|
|
media: ImmutablePropTypes.list,
|
|
|
|
media: ImmutablePropTypes.list,
|
|
|
|
preselectDate: PropTypes.instanceOf(Date),
|
|
|
|
|
|
|
|
privacy: PropTypes.string,
|
|
|
|
|
|
|
|
sideArm: PropTypes.string,
|
|
|
|
sideArm: PropTypes.string,
|
|
|
|
sensitive: PropTypes.bool,
|
|
|
|
sensitive: PropTypes.bool,
|
|
|
|
showSearch: PropTypes.bool,
|
|
|
|
|
|
|
|
spoiler: PropTypes.bool,
|
|
|
|
|
|
|
|
spoilerText: PropTypes.string,
|
|
|
|
|
|
|
|
suggestionToken: PropTypes.string,
|
|
|
|
|
|
|
|
suggestions: ImmutablePropTypes.list,
|
|
|
|
|
|
|
|
text: PropTypes.string,
|
|
|
|
|
|
|
|
anyMedia: PropTypes.bool,
|
|
|
|
|
|
|
|
spoilersAlwaysOn: PropTypes.bool,
|
|
|
|
spoilersAlwaysOn: PropTypes.bool,
|
|
|
|
mediaDescriptionConfirmation: PropTypes.bool,
|
|
|
|
mediaDescriptionConfirmation: PropTypes.bool,
|
|
|
|
preselectOnReply: PropTypes.bool,
|
|
|
|
preselectOnReply: PropTypes.bool,
|
|
|
|
|
|
|
|
|
|
|
|
// Dispatch props.
|
|
|
|
|
|
|
|
onChangeSpoilerText: PropTypes.func,
|
|
|
|
|
|
|
|
onChangeSpoilerness: PropTypes.func,
|
|
|
|
onChangeSpoilerness: PropTypes.func,
|
|
|
|
onChangeText: PropTypes.func,
|
|
|
|
|
|
|
|
onChangeVisibility: PropTypes.func,
|
|
|
|
onChangeVisibility: PropTypes.func,
|
|
|
|
onClearSuggestions: PropTypes.func,
|
|
|
|
|
|
|
|
onFetchSuggestions: PropTypes.func,
|
|
|
|
|
|
|
|
onInsertEmoji: PropTypes.func,
|
|
|
|
|
|
|
|
onMount: PropTypes.func,
|
|
|
|
onMount: PropTypes.func,
|
|
|
|
onSelectSuggestion: PropTypes.func,
|
|
|
|
|
|
|
|
onSubmit: PropTypes.func,
|
|
|
|
|
|
|
|
onUnmount: PropTypes.func,
|
|
|
|
onUnmount: PropTypes.func,
|
|
|
|
onUpload: PropTypes.func,
|
|
|
|
onPaste: PropTypes.func,
|
|
|
|
onMediaDescriptionConfirm: PropTypes.func,
|
|
|
|
onMediaDescriptionConfirm: PropTypes.func,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Changes the text value of the spoiler.
|
|
|
|
static defaultProps = {
|
|
|
|
handleChangeSpoiler = ({ target: { value } }) => {
|
|
|
|
showSearch: false,
|
|
|
|
const { onChangeSpoilerText } = this.props;
|
|
|
|
};
|
|
|
|
if (onChangeSpoilerText) {
|
|
|
|
|
|
|
|
onChangeSpoilerText(value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Inserts an emoji at the caret.
|
|
|
|
|
|
|
|
handleEmoji = (data) => {
|
|
|
|
|
|
|
|
const { textarea: { selectionStart } } = this;
|
|
|
|
|
|
|
|
const { onInsertEmoji } = this.props;
|
|
|
|
|
|
|
|
if (onInsertEmoji) {
|
|
|
|
|
|
|
|
onInsertEmoji(selectionStart, data);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Handles the secondary submit button.
|
|
|
|
|
|
|
|
handleSecondarySubmit = () => {
|
|
|
|
|
|
|
|
const { handleSubmit } = this.handlers;
|
|
|
|
|
|
|
|
const {
|
|
|
|
|
|
|
|
onChangeVisibility,
|
|
|
|
|
|
|
|
sideArm,
|
|
|
|
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
if (sideArm !== 'none' && onChangeVisibility) {
|
|
|
|
|
|
|
|
onChangeVisibility(sideArm);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
handleSubmit();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Selects a suggestion from the autofill.
|
|
|
|
handleChange = (e) => {
|
|
|
|
handleSelect = (tokenStart, token, value) => {
|
|
|
|
this.props.onChange(e.target.value);
|
|
|
|
const { onSelectSuggestion } = this.props;
|
|
|
|
|
|
|
|
if (onSelectSuggestion) {
|
|
|
|
|
|
|
|
onSelectSuggestion(tokenStart, token, value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
handleKeyDown = ({ ctrlKey, keyCode, metaKey, altKey }) => {
|
|
|
|
handleKeyDown = ({ ctrlKey, keyCode, metaKey, altKey }) => {
|
|
|
@ -129,18 +91,10 @@ class ComposeForm extends ImmutablePureComponent {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// When the escape key is released, we focus the UI.
|
|
|
|
|
|
|
|
handleKeyUp = ({ key }) => {
|
|
|
|
|
|
|
|
if (key === 'Escape') {
|
|
|
|
|
|
|
|
document.querySelector('.ui').parentElement.focus();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Submits the status.
|
|
|
|
|
|
|
|
handleSubmit = () => {
|
|
|
|
handleSubmit = () => {
|
|
|
|
const { textarea: { value }, uploadForm } = this;
|
|
|
|
const { textarea: { value }, uploadForm } = this;
|
|
|
|
const {
|
|
|
|
const {
|
|
|
|
onChangeText,
|
|
|
|
onChange,
|
|
|
|
onSubmit,
|
|
|
|
onSubmit,
|
|
|
|
isSubmitting,
|
|
|
|
isSubmitting,
|
|
|
|
isChangingUpload,
|
|
|
|
isChangingUpload,
|
|
|
@ -154,8 +108,8 @@ class ComposeForm extends ImmutablePureComponent {
|
|
|
|
|
|
|
|
|
|
|
|
// If something changes inside the textarea, then we update the
|
|
|
|
// If something changes inside the textarea, then we update the
|
|
|
|
// state before submitting.
|
|
|
|
// state before submitting.
|
|
|
|
if (onChangeText && text !== value) {
|
|
|
|
if (onChange && text !== value) {
|
|
|
|
onChangeText(value);
|
|
|
|
onChange(value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Submit disabled:
|
|
|
|
// Submit disabled:
|
|
|
@ -178,6 +132,48 @@ class ComposeForm extends ImmutablePureComponent {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Changes the text value of the spoiler.
|
|
|
|
|
|
|
|
handleChangeSpoiler = ({ target: { value } }) => {
|
|
|
|
|
|
|
|
const { onChangeSpoilerText } = this.props;
|
|
|
|
|
|
|
|
if (onChangeSpoilerText) {
|
|
|
|
|
|
|
|
onChangeSpoilerText(value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Inserts an emoji at the caret.
|
|
|
|
|
|
|
|
handleEmoji = (data) => {
|
|
|
|
|
|
|
|
const { textarea: { selectionStart } } = this;
|
|
|
|
|
|
|
|
const { onPickEmoji } = this.props;
|
|
|
|
|
|
|
|
if (onPickEmoji) {
|
|
|
|
|
|
|
|
onPickEmoji(selectionStart, data);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Handles the secondary submit button.
|
|
|
|
|
|
|
|
handleSecondarySubmit = () => {
|
|
|
|
|
|
|
|
const { handleSubmit } = this.handlers;
|
|
|
|
|
|
|
|
const {
|
|
|
|
|
|
|
|
onChangeVisibility,
|
|
|
|
|
|
|
|
sideArm,
|
|
|
|
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
if (sideArm !== 'none' && onChangeVisibility) {
|
|
|
|
|
|
|
|
onChangeVisibility(sideArm);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
handleSubmit();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Selects a suggestion from the autofill.
|
|
|
|
|
|
|
|
onSuggestionSelected = (tokenStart, token, value) => {
|
|
|
|
|
|
|
|
this.props.onSuggestionSelected(tokenStart, token, value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// When the escape key is released, we focus the UI.
|
|
|
|
|
|
|
|
handleKeyUp = ({ key }) => {
|
|
|
|
|
|
|
|
if (key === 'Escape') {
|
|
|
|
|
|
|
|
document.querySelector('.ui').parentElement.focus();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Sets a reference to the textarea.
|
|
|
|
// Sets a reference to the textarea.
|
|
|
|
setAutosuggestTextarea = (textareaComponent) => {
|
|
|
|
setAutosuggestTextarea = (textareaComponent) => {
|
|
|
|
if (textareaComponent) {
|
|
|
|
if (textareaComponent) {
|
|
|
@ -265,9 +261,6 @@ class ComposeForm extends ImmutablePureComponent {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
handleChange = (e) => {
|
|
|
|
|
|
|
|
this.props.onChangeText(e.target.value);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
render () {
|
|
|
|
render () {
|
|
|
|
const {
|
|
|
|
const {
|
|
|
@ -279,7 +272,6 @@ class ComposeForm extends ImmutablePureComponent {
|
|
|
|
} = this;
|
|
|
|
} = this;
|
|
|
|
const {
|
|
|
|
const {
|
|
|
|
advancedOptions,
|
|
|
|
advancedOptions,
|
|
|
|
amUnlocked,
|
|
|
|
|
|
|
|
anyMedia,
|
|
|
|
anyMedia,
|
|
|
|
intl,
|
|
|
|
intl,
|
|
|
|
isSubmitting,
|
|
|
|
isSubmitting,
|
|
|
@ -288,11 +280,10 @@ class ComposeForm extends ImmutablePureComponent {
|
|
|
|
layout,
|
|
|
|
layout,
|
|
|
|
media,
|
|
|
|
media,
|
|
|
|
onChangeSpoilerness,
|
|
|
|
onChangeSpoilerness,
|
|
|
|
onChangeText,
|
|
|
|
|
|
|
|
onChangeVisibility,
|
|
|
|
onChangeVisibility,
|
|
|
|
onClearSuggestions,
|
|
|
|
onClearSuggestions,
|
|
|
|
onFetchSuggestions,
|
|
|
|
onFetchSuggestions,
|
|
|
|
onUpload,
|
|
|
|
onPaste,
|
|
|
|
privacy,
|
|
|
|
privacy,
|
|
|
|
sensitive,
|
|
|
|
sensitive,
|
|
|
|
showSearch,
|
|
|
|
showSearch,
|
|
|
@ -343,8 +334,8 @@ class ComposeForm extends ImmutablePureComponent {
|
|
|
|
onKeyDown={this.handleKeyDown}
|
|
|
|
onKeyDown={this.handleKeyDown}
|
|
|
|
onSuggestionsFetchRequested={onFetchSuggestions}
|
|
|
|
onSuggestionsFetchRequested={onFetchSuggestions}
|
|
|
|
onSuggestionsClearRequested={onClearSuggestions}
|
|
|
|
onSuggestionsClearRequested={onClearSuggestions}
|
|
|
|
onSuggestionSelected={this.handleSelect}
|
|
|
|
onSuggestionSelected={this.onSuggestionSelected}
|
|
|
|
onPaste={onUpload}
|
|
|
|
onPaste={onPaste}
|
|
|
|
autoFocus={!showSearch && !isMobile(window.innerWidth, layout)}
|
|
|
|
autoFocus={!showSearch && !isMobile(window.innerWidth, layout)}
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
|
@ -361,7 +352,7 @@ class ComposeForm extends ImmutablePureComponent {
|
|
|
|
disabled={isSubmitting}
|
|
|
|
disabled={isSubmitting}
|
|
|
|
onChangeVisibility={onChangeVisibility}
|
|
|
|
onChangeVisibility={onChangeVisibility}
|
|
|
|
onToggleSpoiler={spoilersAlwaysOn ? null : onChangeSpoilerness}
|
|
|
|
onToggleSpoiler={spoilersAlwaysOn ? null : onChangeSpoilerness}
|
|
|
|
onUpload={onUpload}
|
|
|
|
onPaste={onPaste}
|
|
|
|
privacy={privacy}
|
|
|
|
privacy={privacy}
|
|
|
|
sensitive={sensitive || (spoilersAlwaysOn && spoilerText && spoilerText.length > 0)}
|
|
|
|
sensitive={sensitive || (spoilersAlwaysOn && spoilerText && spoilerText.length > 0)}
|
|
|
|
spoiler={spoilersAlwaysOn ? (spoilerText && spoilerText.length > 0) : spoiler}
|
|
|
|
spoiler={spoilersAlwaysOn ? (spoilerText && spoilerText.length > 0) : spoiler}
|
|
|
|