mirror of
https://github.com/ascribe/onion.git
synced 2025-01-22 23:56:53 +01:00
refactor file size calculation
This commit is contained in:
parent
3307e282e4
commit
1fabea93ff
@ -9,26 +9,11 @@ let FileDragAndDropPreviewProgress = React.createClass({
|
||||
files: React.PropTypes.array
|
||||
},
|
||||
|
||||
calcOverallProgress() {
|
||||
let overallProgress = 0;
|
||||
let sizeOfAllFiles = 0;
|
||||
let files = this.props.files.filter((file) => file.status !== 'deleted' && file.status !== 'canceled' && file.status !== 'online');
|
||||
|
||||
for(let i = 0; i < files.length; i++) {
|
||||
sizeOfAllFiles += files[i].size;
|
||||
}
|
||||
|
||||
for(let i = 0; i < files.length; i++) {
|
||||
overallProgress += files[i].size / sizeOfAllFiles * files[i].progress;
|
||||
}
|
||||
|
||||
return overallProgress;
|
||||
},
|
||||
|
||||
calcOverallFileSize() {
|
||||
let overallFileSize = 0;
|
||||
let files = this.props.files.filter((file) => file.status !== 'deleted' && file.status !== 'canceled' && file.status !== 'online');
|
||||
|
||||
// We just sum up all files' sizes
|
||||
for(let i = 0; i < files.length; i++) {
|
||||
overallFileSize += files[i].size;
|
||||
}
|
||||
@ -36,6 +21,20 @@ let FileDragAndDropPreviewProgress = React.createClass({
|
||||
return overallFileSize;
|
||||
},
|
||||
|
||||
calcOverallProgress() {
|
||||
let overallProgress = 0;
|
||||
let overallFileSize = this.calcOverallFileSize();
|
||||
let files = this.props.files.filter((file) => file.status !== 'deleted' && file.status !== 'canceled' && file.status !== 'online');
|
||||
|
||||
// We calculate the overall progress by summing the individuals
|
||||
// files' progresses in relation to their size
|
||||
for(let i = 0; i < files.length; i++) {
|
||||
overallProgress += files[i].size / overallFileSize * files[i].progress;
|
||||
}
|
||||
|
||||
return overallProgress;
|
||||
},
|
||||
|
||||
render() {
|
||||
let overallProgress = this.calcOverallProgress();
|
||||
let overallFileSize = this.calcOverallFileSize();
|
||||
|
Loading…
Reference in New Issue
Block a user