From e84c1dc95fbd23895e7abc34148750c35e90c4b2 Mon Sep 17 00:00:00 2001 From: Kibigo Date: Tue, 28 Feb 2017 18:52:46 -0800 Subject: Support for pasting images from clipboard --- .../components/components/autosuggest_textarea.jsx | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'app/assets') diff --git a/app/assets/javascripts/components/components/autosuggest_textarea.jsx b/app/assets/javascripts/components/components/autosuggest_textarea.jsx index 590658671..51be39379 100644 --- a/app/assets/javascripts/components/components/autosuggest_textarea.jsx +++ b/app/assets/javascripts/components/components/autosuggest_textarea.jsx @@ -1,6 +1,8 @@ import AutosuggestAccountContainer from '../features/compose/containers/autosuggest_account_container'; import ImmutablePropTypes from 'react-immutable-proptypes'; import { isRtl } from '../rtl'; +import { connect } from 'react-redux'; +import { uploadCompose } from '../actions/compose'; const textAtCursorMatchesToken = (str, caretPosition) => { let word; @@ -33,6 +35,7 @@ const AutosuggestTextarea = React.createClass({ value: React.PropTypes.string, suggestions: ImmutablePropTypes.list, disabled: React.PropTypes.bool, + dispatch: React.PropTypes.func.isRequired, fileDropDate: React.PropTypes.instanceOf(Date), placeholder: React.PropTypes.string, onSuggestionSelected: React.PropTypes.func.isRequired, @@ -173,6 +176,13 @@ const AutosuggestTextarea = React.createClass({ }) }, + onPaste (e) { + if (e.clipboardData && e.clipboardData.files.length === 1) { + this.props.dispatch(uploadCompose(e.clipboardData.files)); + e.preventDefault(); + } + }, + render () { const { value, suggestions, fileDropDate, disabled, placeholder, onKeyUp } = this.props; const { isFileDragging, suggestionsHidden, selectedSuggestion } = this.state; @@ -198,6 +208,7 @@ const AutosuggestTextarea = React.createClass({ onBlur={this.onBlur} onDragEnter={this.onDragEnter} onDragExit={this.onDragExit} + onPaste={this.onPaste} style={style} /> @@ -214,4 +225,4 @@ const AutosuggestTextarea = React.createClass({ }); -export default AutosuggestTextarea; +export default connect()(AutosuggestTextarea); -- cgit From 91c79f2445a10d0f43254fc44656152ae88fd9cd Mon Sep 17 00:00:00 2001 From: Kibigo Date: Wed, 1 Mar 2017 02:56:15 -0800 Subject: Better smart/dumb component separation --- .../javascripts/components/components/autosuggest_textarea.jsx | 10 ++++------ .../components/features/compose/components/compose_form.jsx | 6 ++++++ .../features/compose/containers/compose_form_container.jsx | 5 +++++ 3 files changed, 15 insertions(+), 6 deletions(-) (limited to 'app/assets') diff --git a/app/assets/javascripts/components/components/autosuggest_textarea.jsx b/app/assets/javascripts/components/components/autosuggest_textarea.jsx index 51be39379..38deeae0e 100644 --- a/app/assets/javascripts/components/components/autosuggest_textarea.jsx +++ b/app/assets/javascripts/components/components/autosuggest_textarea.jsx @@ -1,8 +1,6 @@ import AutosuggestAccountContainer from '../features/compose/containers/autosuggest_account_container'; import ImmutablePropTypes from 'react-immutable-proptypes'; import { isRtl } from '../rtl'; -import { connect } from 'react-redux'; -import { uploadCompose } from '../actions/compose'; const textAtCursorMatchesToken = (str, caretPosition) => { let word; @@ -35,7 +33,6 @@ const AutosuggestTextarea = React.createClass({ value: React.PropTypes.string, suggestions: ImmutablePropTypes.list, disabled: React.PropTypes.bool, - dispatch: React.PropTypes.func.isRequired, fileDropDate: React.PropTypes.instanceOf(Date), placeholder: React.PropTypes.string, onSuggestionSelected: React.PropTypes.func.isRequired, @@ -43,7 +40,8 @@ const AutosuggestTextarea = React.createClass({ onSuggestionsFetchRequested: React.PropTypes.func.isRequired, onChange: React.PropTypes.func.isRequired, onKeyUp: React.PropTypes.func, - onKeyDown: React.PropTypes.func + onKeyDown: React.PropTypes.func, + onPaste: React.PropTypes.func.isRequired, }, getInitialState () { @@ -178,7 +176,7 @@ const AutosuggestTextarea = React.createClass({ onPaste (e) { if (e.clipboardData && e.clipboardData.files.length === 1) { - this.props.dispatch(uploadCompose(e.clipboardData.files)); + this.props.onPaste(e.clipboardData.files) e.preventDefault(); } }, @@ -225,4 +223,4 @@ const AutosuggestTextarea = React.createClass({ }); -export default connect()(AutosuggestTextarea); +export default AutosuggestTextarea; diff --git a/app/assets/javascripts/components/features/compose/components/compose_form.jsx b/app/assets/javascripts/components/features/compose/components/compose_form.jsx index 31ae8e034..a71f5b0fd 100644 --- a/app/assets/javascripts/components/features/compose/components/compose_form.jsx +++ b/app/assets/javascripts/components/features/compose/components/compose_form.jsx @@ -47,6 +47,7 @@ const ComposeForm = React.createClass({ onFetchSuggestions: React.PropTypes.func.isRequired, onSuggestionSelected: React.PropTypes.func.isRequired, onChangeSpoilerText: React.PropTypes.func.isRequired, + onPaste: React.PropTypes.func.isRequired, }, mixins: [PureRenderMixin], @@ -82,6 +83,10 @@ const ComposeForm = React.createClass({ this.props.onChangeSpoilerText(e.target.value); }, + onPaste (files) { + this.props.onPaste(files); + }, + componentDidUpdate (prevProps) { if (this.props.focusDate !== prevProps.focusDate) { // If replying to zero or one users, places the cursor at the end of the textbox. @@ -149,6 +154,7 @@ const ComposeForm = React.createClass({ onSuggestionsFetchRequested={this.onSuggestionsFetchRequested} onSuggestionsClearRequested={this.onSuggestionsClearRequested} onSuggestionSelected={this.onSuggestionSelected} + onPaste={this.onPaste} />
diff --git a/app/assets/javascripts/components/features/compose/containers/compose_form_container.jsx b/app/assets/javascripts/components/features/compose/containers/compose_form_container.jsx index 53129af6e..a34201747 100644 --- a/app/assets/javascripts/components/features/compose/containers/compose_form_container.jsx +++ b/app/assets/javascripts/components/features/compose/containers/compose_form_container.jsx @@ -1,5 +1,6 @@ import { connect } from 'react-redux'; import ComposeForm from '../components/compose_form'; +import { uploadCompose } from '../../../actions/compose'; import { createSelector } from 'reselect'; import { changeCompose, @@ -65,6 +66,10 @@ const mapDispatchToProps = (dispatch) => ({ dispatch(changeComposeSpoilerText(checked)); }, + onPaste (files) { + dispatch(uploadCompose(files)); + }, + }); export default connect(mapStateToProps, mapDispatchToProps)(ComposeForm); -- cgit From 95ebfa5610577426a5a8f5b6aee83af83dd4a9b4 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Wed, 1 Mar 2017 13:57:30 +0100 Subject: Simplify passing of prop --- .../components/features/compose/components/compose_form.jsx | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'app/assets') diff --git a/app/assets/javascripts/components/features/compose/components/compose_form.jsx b/app/assets/javascripts/components/features/compose/components/compose_form.jsx index a71f5b0fd..bcc4fe1e7 100644 --- a/app/assets/javascripts/components/features/compose/components/compose_form.jsx +++ b/app/assets/javascripts/components/features/compose/components/compose_form.jsx @@ -83,10 +83,6 @@ const ComposeForm = React.createClass({ this.props.onChangeSpoilerText(e.target.value); }, - onPaste (files) { - this.props.onPaste(files); - }, - componentDidUpdate (prevProps) { if (this.props.focusDate !== prevProps.focusDate) { // If replying to zero or one users, places the cursor at the end of the textbox. @@ -105,7 +101,7 @@ const ComposeForm = React.createClass({ }, render () { - const { intl, needsPrivacyWarning, mentionedDomains } = this.props; + const { intl, needsPrivacyWarning, mentionedDomains, onPaste } = this.props; const disabled = this.props.is_submitting || this.props.is_uploading; let publishText = ''; @@ -154,7 +150,7 @@ const ComposeForm = React.createClass({ onSuggestionsFetchRequested={this.onSuggestionsFetchRequested} onSuggestionsClearRequested={this.onSuggestionsClearRequested} onSuggestionSelected={this.onSuggestionSelected} - onPaste={this.onPaste} + onPaste={onPaste} />
-- cgit