diff --git a/src/core/Core.js b/src/core/Core.js index f71374e39..59a5061d9 100644 --- a/src/core/Core.js +++ b/src/core/Core.js @@ -145,7 +145,7 @@ export default class Core { this.bus.emit('file-added', fileID) if (fileTypeGeneral === 'image' && !isRemote) { - this.addFileThumbnail(newFile.id) + this.addThumbnail(newFile.id) } if (this.opts.autoProceed) { @@ -153,11 +153,17 @@ export default class Core { } } - addFileThumbnail (fileID) { + removeFile (fileID) { + const updatedFiles = Object.assign({}, this.getState().files) + delete updatedFiles[fileID] + this.setState({files: updatedFiles}) + } + + addThumbnail (fileID) { const file = this.getState().files[fileID] Utils.readFile(file.data) - .then(Utils.createImageThumbnail) + .then((imgDataURI) => Utils.createImageThumbnail(imgDataURI, 200)) .then((thumbnail) => { const updatedFiles = Object.assign({}, this.getState().files) const updatedFile = Object.assign({}, updatedFiles[fileID], { @@ -181,24 +187,20 @@ export default class Core { // const bus = this.bus - this.on('file-add', (data) => { + this.on('core:file-add', (data) => { this.addFile(data) }) // `remove-file` removes a file from `state.files`, for example when // a user decides not to upload particular file and clicks a button to remove it - this.on('file-remove', (fileID) => { - const updatedFiles = Object.assign({}, this.getState().files) - delete updatedFiles[fileID] - this.setState({files: updatedFiles}) + this.on('core:file-remove', (fileID) => { + this.removeFile(fileID) }) - this.on('core:file-upload-started', (fileID, upload) => { + this.on('core:upload-started', (fileID, upload) => { const updatedFiles = Object.assign({}, this.getState().files) const updatedFile = Object.assign({}, updatedFiles[fileID], Object.assign({}, { - // can’t do that, because immutability. ?? - // upload: upload, progress: Object.assign({}, updatedFiles[fileID].progress, { uploadStarted: Date.now() }) @@ -209,7 +211,8 @@ export default class Core { this.setState({files: updatedFiles}) }) - this.on('upload-progress', (data) => { + this.on('core:upload-progress', (data) => { + console.log(data) const fileID = data.id const updatedFiles = Object.assign({}, this.getState().files) if (!updatedFiles[fileID]) { @@ -231,16 +234,15 @@ export default class Core { // calculate total progress, using the number of files currently uploading, // multiplied by 100 and the summ of individual progress of each file const inProgress = Object.keys(updatedFiles).filter((file) => { - return !updatedFiles[file].progress.uploadComplete && - updatedFiles[file].progress.uploadStarted + return updatedFiles[file].progress.uploadStarted }) - const progressMax = Object.keys(inProgress).length * 100 + const progressMax = inProgress.length * 100 let progressAll = 0 inProgress.forEach((file) => { progressAll = progressAll + updatedFiles[file].progress.percentage }) - const totalProgress = progressAll * 100 / progressMax + const totalProgress = Math.round((progressAll * 100 / progressMax).toFixed(2)) if (totalProgress === 100) { const completeFiles = Object.keys(updatedFiles).filter((file) => { @@ -256,7 +258,7 @@ export default class Core { }) }) - this.on('upload-success', (fileID, uploadURL) => { + this.on('core:upload-success', (fileID, uploadURL) => { const updatedFiles = Object.assign({}, this.getState().files) const updatedFile = Object.assign({}, updatedFiles[fileID], { progress: Object.assign({}, updatedFiles[fileID].progress, { @@ -284,7 +286,6 @@ export default class Core { } isOnline (status) { - // const bus = this.bus const online = status || window.navigator.onLine if (!online) { this.emit('is-offline') diff --git a/src/plugins/Dashboard/Dashboard.js b/src/plugins/Dashboard/Dashboard.js index 9c1f1619f..bb4b816e8 100644 --- a/src/plugins/Dashboard/Dashboard.js +++ b/src/plugins/Dashboard/Dashboard.js @@ -22,13 +22,7 @@ export default function Dashboard (props) { }) const removeFile = (fileID) => { - // this seems to be working in latest Chrome, Firefox and Safari, - // // but might not be 100% cross-browser, needs testing - // // https://davidwalsh.name/css-animation-callback - // // el.addEventListener('animationend', () => { - // // bus.emit('file-remove', file.id) - // // }) - props.bus.emit('file-remove', fileID) + props.bus.emit('core:file-remove', fileID) } const startUpload = (ev) => { @@ -58,7 +52,7 @@ export default function Dashboard (props) { const files = toArray(ev.target.files) files.forEach((file) => { - props.bus.emit('file-add', { + props.bus.emit('core:file-add', { source: props.id, name: file.name, type: file.type, @@ -73,8 +67,7 @@ export default function Dashboard (props) { aria-hidden="${props.inline ? 'false' : modal.isHidden}" aria-label="${!props.inline ? props.i18n('dashboardWindowTitle') - : props.i18n('dashboardTitle') - }" + : props.i18n('dashboardTitle')}" role="dialog" onpaste=${props.onPaste}> diff --git a/src/plugins/DragDrop/index.js b/src/plugins/DragDrop/index.js index f16ed5cbd..fb933e74e 100644 --- a/src/plugins/DragDrop/index.js +++ b/src/plugins/DragDrop/index.js @@ -87,8 +87,7 @@ export default class DragDrop extends Plugin { const files = toArray(ev.target.files) files.forEach((file) => { - console.log(file) - this.core.emitter.emit('file-add', { + this.core.emitter.emit('core:file-add', { source: this.id, name: file.name, type: file.type, @@ -101,7 +100,6 @@ export default class DragDrop extends Plugin { const firstInput = document.querySelector(`${this.target} .UppyDragDrop-focus`) // only works for the first time if wrapped in setTimeout for some reason - // firstInput.focus() setTimeout(function () { firstInput.focus() }, 10) diff --git a/src/plugins/Tus10.js b/src/plugins/Tus10.js index 3f0077425..14973e86e 100644 --- a/src/plugins/Tus10.js +++ b/src/plugins/Tus10.js @@ -96,7 +96,7 @@ export default class Tus10 extends Plugin { }, onProgress: (bytesUploaded, bytesTotal) => { // Dispatch progress event - this.core.emitter.emit('upload-progress', { + this.core.emitter.emit('core:upload-progress', { uploader: this, id: file.id, bytesUploaded: bytesUploaded, @@ -104,14 +104,14 @@ export default class Tus10 extends Plugin { }) }, onSuccess: () => { - this.core.emitter.emit('upload-success', file.id, upload.url) + this.core.emitter.emit('core:upload-success', file.id, upload.url) this.core.log(`Download ${upload.file.name} from ${upload.url}`) resolve(upload) } }) - this.core.emitter.on('file-remove', (fileID) => { + this.core.emitter.on('core:file-remove', (fileID) => { if (fileID === file.id) { console.log('removing file: ', fileID) upload.abort() @@ -139,7 +139,7 @@ export default class Tus10 extends Plugin { }) upload.start() - this.core.emitter.emit('core:file-upload-started', file.id, upload) + this.core.emitter.emit('core:upload-started', file.id, upload) }) } @@ -181,7 +181,7 @@ export default class Tus10 extends Plugin { this.core.log(`Upload progress: ${progress}`) // Dispatch progress event - this.core.emitter.emit('upload-progress', { + this.core.emitter.emit('core:upload-progress', { uploader: this, id: file.id, bytesUploaded: bytesUploaded, @@ -214,12 +214,11 @@ export default class Tus10 extends Plugin { return Promise.all(uploaders) .then(() => { - return { - uploadedCount: files.length - } - }) - .catch(() => { this.core.log('All files uploaded') + return { uploadedCount: files.length } + }) + .catch((err) => { + this.core.log('Upload error: ' + err) }) } diff --git a/src/plugins/Webcam/index.js b/src/plugins/Webcam/index.js index a9c8c7084..97dc71203 100644 --- a/src/plugins/Webcam/index.js +++ b/src/plugins/Webcam/index.js @@ -89,7 +89,7 @@ export default class Webcam extends Plugin { type: opts.mimeType } - this.core.emitter.emit('file-add', tagFile) + this.core.emitter.emit('core:file-add', tagFile) } render (state) {