diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2019-09-16 20:42:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-16 20:42:19 +0200 |
commit | bdeff5ae1585a8087ec2d02cd8cb07af319c3d58 (patch) | |
tree | 22898ba2157017c95f8fcb2448e66164e557f3c0 /app | |
parent | d256901f60b121172ae3a3a7167f9c64d947cf99 (diff) |
Fix web UI allowing uploads past status limit via drag & drop (#11863)
Fix #11659
Diffstat (limited to 'app')
-rw-r--r-- | app/javascript/mastodon/features/ui/index.js | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/app/javascript/mastodon/features/ui/index.js b/app/javascript/mastodon/features/ui/index.js index 63c5622b6..f5e48ed31 100644 --- a/app/javascript/mastodon/features/ui/index.js +++ b/app/javascript/mastodon/features/ui/index.js @@ -66,6 +66,7 @@ const mapStateToProps = state => ({ isComposing: state.getIn(['compose', 'is_composing']), hasComposingText: state.getIn(['compose', 'text']).trim().length !== 0, hasMediaAttachments: state.getIn(['compose', 'media_attachments']).size > 0, + canUploadMore: !state.getIn(['compose', 'media_attachments']).some(x => ['audio', 'video'].includes(x.get('type'))) && state.getIn(['compose', 'media_attachments']).size < 4, dropdownMenuIsOpen: state.getIn(['dropdown_menu', 'openId']) !== null, }); @@ -232,6 +233,7 @@ class UI extends React.PureComponent { isComposing: PropTypes.bool, hasComposingText: PropTypes.bool, hasMediaAttachments: PropTypes.bool, + canUploadMore: PropTypes.bool, location: PropTypes.object, intl: PropTypes.object.isRequired, dropdownMenuIsOpen: PropTypes.bool, @@ -278,13 +280,14 @@ class UI extends React.PureComponent { this.dragTargets.push(e.target); } - if (e.dataTransfer && Array.from(e.dataTransfer.types).includes('Files')) { + if (e.dataTransfer && Array.from(e.dataTransfer.types).includes('Files') && this.props.canUploadMore) { this.setState({ draggingOver: true }); } } handleDragOver = (e) => { if (this.dataTransferIsText(e.dataTransfer)) return false; + e.preventDefault(); e.stopPropagation(); @@ -299,12 +302,13 @@ class UI extends React.PureComponent { handleDrop = (e) => { if (this.dataTransferIsText(e.dataTransfer)) return; + e.preventDefault(); this.setState({ draggingOver: false }); this.dragTargets = []; - if (e.dataTransfer && e.dataTransfer.files.length >= 1) { + if (e.dataTransfer && e.dataTransfer.files.length >= 1 && this.props.canUploadMore) { this.props.dispatch(uploadCompose(e.dataTransfer.files)); } } |