diff options
author | Mika Andrianarijaona <mikaoelitiana@users.noreply.github.com> | 2017-01-19 00:00:21 +0300 |
---|---|---|
committer | enahum <nahumhbl@gmail.com> | 2017-01-18 18:00:21 -0300 |
commit | 9eb57278413d4a4417e574f2bddb5bc0b2807d14 (patch) | |
tree | 3316c7482c24a7f47e994b42d8e7332002359592 /webapp/components/file_upload.jsx | |
parent | e15ae2253a15c7951c31ce0a2f9eea188ba2b639 (diff) | |
download | chat-9eb57278413d4a4417e574f2bddb5bc0b2807d14.tar.gz chat-9eb57278413d4a4417e574f2bddb5bc0b2807d14.tar.bz2 chat-9eb57278413d4a4417e574f2bddb5bc0b2807d14.zip |
PLT-137: Disable upload button when max uploads reached (#5053)
* Change upload button color opacity when max reached
* Display max upload message
* Remove error when deleting preview
* Clear error message in side-bar
when user reaches max upload and error is displayed in side-bar, removing one file won't remove error message
* Scroll in preview after file upload in sidebar
Diffstat (limited to 'webapp/components/file_upload.jsx')
-rw-r--r-- | webapp/components/file_upload.jsx | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/webapp/components/file_upload.jsx b/webapp/components/file_upload.jsx index 9eff25ab5..36beb8c91 100644 --- a/webapp/components/file_upload.jsx +++ b/webapp/components/file_upload.jsx @@ -47,6 +47,7 @@ class FileUpload extends React.Component { this.cancelUpload = this.cancelUpload.bind(this); this.pasteUpload = this.pasteUpload.bind(this); this.keyUpload = this.keyUpload.bind(this); + this.handleMaxUploadReached = this.handleMaxUploadReached.bind(this); this.state = { requests: {} @@ -309,6 +310,16 @@ class FileUpload extends React.Component { } } + handleMaxUploadReached(e) { + e.preventDefault(); + + const {formatMessage} = this.props.intl; + + this.props.onUploadError(formatMessage(holders.limited, {count: Constants.MAX_UPLOAD_FILES})); + + return false; + } + render() { let multiple = true; if (UserAgent.isMobileApp()) { @@ -322,10 +333,14 @@ class FileUpload extends React.Component { accept = 'image/*'; } + const channelId = this.props.channelId || ChannelStore.getCurrentId(); + + const uploadsRemaining = Constants.MAX_UPLOAD_FILES - this.props.getFileCount(channelId); + return ( <span ref='input' - className='btn btn-file' + className={'btn btn-file' + (uploadsRemaining <= 0 ? ' btn-file__disabled' : '')} > <span className='icon' @@ -335,7 +350,7 @@ class FileUpload extends React.Component { ref='fileInput' type='file' onChange={this.handleChange} - onClick={this.props.onClick} + onClick={uploadsRemaining > 0 ? this.props.onClick : this.handleMaxUploadReached} multiple={multiple} accept={accept} /> |