Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "Fix incorrect behavior during file upload - #1525" #1558

Merged
merged 1 commit into from
Sep 10, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 15 additions & 23 deletions src/components/fileupload/FileUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ export class FileUpload extends Component {
this.state = {
files: [],
msgs: [],
focused: false,
uploading: false
focused: false
};

this.choose = this.choose.bind(this);
Expand Down Expand Up @@ -110,15 +109,15 @@ export class FileUpload extends Component {
}

chooseDisabled() {
return this.props.disabled || (this.props.fileLimit && this.props.fileLimit <= this.state.files.length + this.uploadedFileCount) || this.state.uploading;
return this.props.disabled || (this.props.fileLimit && this.props.fileLimit <= this.state.files.length + this.uploadedFileCount);
}

uploadDisabled() {
return this.props.disabled || !this.hasFiles() || this.state.uploading;
return this.props.disabled || !this.hasFiles();
}

cancelDisabled() {
return this.props.disabled || !this.hasFiles() || this.state.uploading;
return this.props.disabled || !this.hasFiles();
}

remove(event, index) {
Expand Down Expand Up @@ -281,10 +280,7 @@ export class FileUpload extends Component {

xhr.onreadystatechange = () => {
if (xhr.readyState === 4) {
this.setState({
progress: 0,
uploading: false
});
this.setState({ progress: 0 });

if (xhr.status >= 200 && xhr.status < 300) {
if (this.props.fileLimit) {
Expand Down Expand Up @@ -317,8 +313,6 @@ export class FileUpload extends Component {
xhr.withCredentials = this.props.withCredentials;

xhr.send(formData);

this.setState({ uploading: true });
}
}

Expand Down Expand Up @@ -349,28 +343,28 @@ export class FileUpload extends Component {
}

onDragEnter(event) {
if (!this.props.disabled && !this.state.uploading) {
if(!this.props.disabled) {
event.stopPropagation();
event.preventDefault();
}
}

onDragOver(event) {
if (!this.props.disabled && !this.state.uploading) {
if (!this.props.disabled) {
DomHandler.addClass(this.content, 'p-fileupload-highlight');
event.stopPropagation();
event.preventDefault();
}
}

onDragLeave(event) {
if (!this.props.disabled && !this.state.uploading) {
if (!this.props.disabled) {
DomHandler.removeClass(this.content, 'p-fileupload-highlight');
}
}

onDrop(event) {
if (!this.props.disabled && !this.state.uploading) {
if (!this.props.disabled) {
DomHandler.removeClass(this.content, 'p-fileupload-highlight');
event.stopPropagation();
event.preventDefault();
Expand All @@ -385,13 +379,11 @@ export class FileUpload extends Component {
}

onSimpleUploaderClick() {
if (!this.state.uploading) {
if (this.hasFiles()) {
this.upload();
}
else {
this.fileInput.click();
}
if (this.hasFiles()) {
this.upload();
}
else {
this.fileInput.click();
}
}

Expand Down Expand Up @@ -420,7 +412,7 @@ export class FileUpload extends Component {
let preview = this.isImage(file) ? <div><img alt={file.name} role="presentation" src={file.objectURL} width={this.props.previewWidth} /></div> : null;
let fileName = <div>{file.name}</div>;
let size = <div>{this.formatSize(file.size)}</div>;
let removeButton = <div><Button type="button" icon="pi pi-times" onClick={(e) => this.remove(e, index)} disabled={this.state.uploading} /></div>
let removeButton = <div><Button type="button" icon="pi pi-times" onClick={(e) => this.remove(e, index)} /></div>

return <div className="p-fileupload-row" key={file.name + file.type + file.size}>
{preview}
Expand Down