From 009df5bad5f55c7e4c698f9dab8420d00a7ae71e Mon Sep 17 00:00:00 2001 From: JoramWilander Date: Mon, 22 Jun 2015 08:35:24 -0400 Subject: fixes mm-1318 only allow 5 files to be uploaded at a time --- web/react/components/create_comment.jsx | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'web/react/components/create_comment.jsx') diff --git a/web/react/components/create_comment.jsx b/web/react/components/create_comment.jsx index 9bcbad079..bb7027115 100644 --- a/web/react/components/create_comment.jsx +++ b/web/react/components/create_comment.jsx @@ -112,13 +112,28 @@ module.exports = React.createClass({ return { messageText: '', uploadsInProgress: 0, previews: [], submitting: false }; }, setUploads: function(val) { - var num = this.state.uploadsInProgress + val; - this.setState({uploadsInProgress: num}); + var oldInProgress = this.state.uploadsInProgress + var newInProgress = oldInProgress + val; + + if (newInProgress + this.state.previews.length > Constants.MAX_UPLOAD_FILES) { + newInProgress = Constants.MAX_UPLOAD_FILES - this.state.previews.length; + this.setState({limit_error: "Uploads limited to " + Constants.MAX_UPLOAD_FILES + " files maximum. Please use additional comments for more files."}); + } else { + this.setState({limit_error: null}); + } + + var numToUpload = newInProgress - oldInProgress; + if (numToUpload <= 0) return 0; + + this.setState({uploadsInProgress: newInProgress}); + + return numToUpload; }, render: function() { var server_error = this.state.server_error ?
: null; var post_error = this.state.post_error ? : null; + var limit_error = this.state.limit_error ?
: null; var preview =
; if (this.state.previews.length > 0 || this.state.uploadsInProgress > 0) { @@ -129,13 +144,6 @@ module.exports = React.createClass({ uploadsInProgress={this.state.uploadsInProgress} /> ); } - var limit_previews = "" - if (this.state.previews.length > 5) { - limit_previews =
- } - if (this.state.previews.length > 20) { - limit_previews =
- } return (
@@ -159,7 +167,7 @@ module.exports = React.createClass({ { post_error } { server_error } - { limit_previews } + { limit_error }
{ preview } -- cgit v1.2.3-1-g7c22