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
Этот коммит содержится в:
коммит произвёл
enahum
родитель
e15ae2253a
Коммит
9eb5727841
@@ -331,6 +331,9 @@ export default class CreateComment extends React.Component {
|
|||||||
draft.fileInfos = draft.fileInfos.concat(fileInfos);
|
draft.fileInfos = draft.fileInfos.concat(fileInfos);
|
||||||
PostStore.storeCommentDraft(this.props.rootId, draft);
|
PostStore.storeCommentDraft(this.props.rootId, draft);
|
||||||
|
|
||||||
|
// Focus on preview if needed
|
||||||
|
this.refs.preview.refs.container.scrollIntoViewIfNeeded();
|
||||||
|
|
||||||
this.setState({uploadsInProgress: draft.uploadsInProgress, fileInfos: draft.fileInfos});
|
this.setState({uploadsInProgress: draft.uploadsInProgress, fileInfos: draft.fileInfos});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -355,6 +358,9 @@ export default class CreateComment extends React.Component {
|
|||||||
const fileInfos = this.state.fileInfos;
|
const fileInfos = this.state.fileInfos;
|
||||||
const uploadsInProgress = this.state.uploadsInProgress;
|
const uploadsInProgress = this.state.uploadsInProgress;
|
||||||
|
|
||||||
|
// Clear previous errors
|
||||||
|
this.handleUploadError(null);
|
||||||
|
|
||||||
// id can either be the id of an uploaded file or the client id of an in progress upload
|
// id can either be the id of an uploaded file or the client id of an in progress upload
|
||||||
let index = fileInfos.findIndex((info) => info.id === id);
|
let index = fileInfos.findIndex((info) => info.id === id);
|
||||||
if (index === -1) {
|
if (index === -1) {
|
||||||
@@ -432,6 +438,7 @@ export default class CreateComment extends React.Component {
|
|||||||
fileInfos={this.state.fileInfos}
|
fileInfos={this.state.fileInfos}
|
||||||
onRemove={this.removePreview}
|
onRemove={this.removePreview}
|
||||||
uploadsInProgress={this.state.uploadsInProgress}
|
uploadsInProgress={this.state.uploadsInProgress}
|
||||||
|
ref='preview'
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -297,6 +297,9 @@ export default class CreatePost extends React.Component {
|
|||||||
const fileInfos = Object.assign([], this.state.fileInfos);
|
const fileInfos = Object.assign([], this.state.fileInfos);
|
||||||
const uploadsInProgress = this.state.uploadsInProgress;
|
const uploadsInProgress = this.state.uploadsInProgress;
|
||||||
|
|
||||||
|
// Clear previous errors
|
||||||
|
this.handleUploadError(null);
|
||||||
|
|
||||||
// id can either be the id of an uploaded file or the client id of an in progress upload
|
// id can either be the id of an uploaded file or the client id of an in progress upload
|
||||||
let index = fileInfos.findIndex((info) => info.id === id);
|
let index = fileInfos.findIndex((info) => info.id === id);
|
||||||
if (index === -1) {
|
if (index === -1) {
|
||||||
|
|||||||
@@ -84,7 +84,10 @@ export default class FilePreview extends React.Component {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='file-preview__container'>
|
<div
|
||||||
|
className='file-preview__container'
|
||||||
|
ref='container'
|
||||||
|
>
|
||||||
{previews}
|
{previews}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ class FileUpload extends React.Component {
|
|||||||
this.cancelUpload = this.cancelUpload.bind(this);
|
this.cancelUpload = this.cancelUpload.bind(this);
|
||||||
this.pasteUpload = this.pasteUpload.bind(this);
|
this.pasteUpload = this.pasteUpload.bind(this);
|
||||||
this.keyUpload = this.keyUpload.bind(this);
|
this.keyUpload = this.keyUpload.bind(this);
|
||||||
|
this.handleMaxUploadReached = this.handleMaxUploadReached.bind(this);
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
requests: {}
|
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() {
|
render() {
|
||||||
let multiple = true;
|
let multiple = true;
|
||||||
if (UserAgent.isMobileApp()) {
|
if (UserAgent.isMobileApp()) {
|
||||||
@@ -322,10 +333,14 @@ class FileUpload extends React.Component {
|
|||||||
accept = 'image/*';
|
accept = 'image/*';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const channelId = this.props.channelId || ChannelStore.getCurrentId();
|
||||||
|
|
||||||
|
const uploadsRemaining = Constants.MAX_UPLOAD_FILES - this.props.getFileCount(channelId);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span
|
<span
|
||||||
ref='input'
|
ref='input'
|
||||||
className='btn btn-file'
|
className={'btn btn-file' + (uploadsRemaining <= 0 ? ' btn-file__disabled' : '')}
|
||||||
>
|
>
|
||||||
<span
|
<span
|
||||||
className='icon'
|
className='icon'
|
||||||
@@ -335,7 +350,7 @@ class FileUpload extends React.Component {
|
|||||||
ref='fileInput'
|
ref='fileInput'
|
||||||
type='file'
|
type='file'
|
||||||
onChange={this.handleChange}
|
onChange={this.handleChange}
|
||||||
onClick={this.props.onClick}
|
onClick={uploadsRemaining > 0 ? this.props.onClick : this.handleMaxUploadReached}
|
||||||
multiple={multiple}
|
multiple={multiple}
|
||||||
accept={accept}
|
accept={accept}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -437,6 +437,15 @@
|
|||||||
@include opacity(.9);
|
@include opacity(.9);
|
||||||
box-shadow: none;
|
box-shadow: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
&.btn-file__disabled {
|
||||||
|
@include opacity(.1);
|
||||||
|
|
||||||
|
&:hover,
|
||||||
|
&:active {
|
||||||
|
@include opacity(.1);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
textarea {
|
textarea {
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user