|
@@ -21,6 +21,14 @@ import {
|
|
|
import packageJson from '../package.json'
|
|
|
import locale from './locale.js'
|
|
|
|
|
|
+
|
|
|
+const getDefaultUploadState = () => ({
|
|
|
+ totalProgress: 0,
|
|
|
+ allowNewUpload: true,
|
|
|
+ error: null,
|
|
|
+ recoveredState: null,
|
|
|
+});
|
|
|
+
|
|
|
/**
|
|
|
* Uppy Core module.
|
|
|
* Manages plugins, state updates, acts as an event bus,
|
|
@@ -91,19 +99,17 @@ class Uppy {
|
|
|
|
|
|
this.store = this.opts.store
|
|
|
this.setState({
|
|
|
+ ...getDefaultUploadState(),
|
|
|
plugins: {},
|
|
|
files: {},
|
|
|
currentUploads: {},
|
|
|
- allowNewUpload: true,
|
|
|
capabilities: {
|
|
|
uploadProgress: supportsUploadProgress(),
|
|
|
individualCancellation: true,
|
|
|
resumableUploads: false,
|
|
|
},
|
|
|
- totalProgress: 0,
|
|
|
meta: { ...this.opts.meta },
|
|
|
info: [],
|
|
|
- recoveredState: null,
|
|
|
})
|
|
|
|
|
|
this.#restricter = new Restricter(() => this.opts, this.i18n)
|
|
@@ -230,6 +236,7 @@ class Uppy {
|
|
|
this.setState() // so that UI re-renders with new options
|
|
|
}
|
|
|
|
|
|
+ // todo next major: rename to something better? (it doesn't just reset progress)
|
|
|
resetProgress () {
|
|
|
const defaultProgress = {
|
|
|
percentage: 0,
|
|
@@ -249,17 +256,16 @@ class Uppy {
|
|
|
}
|
|
|
})
|
|
|
|
|
|
- this.setState({
|
|
|
- files: updatedFiles,
|
|
|
- totalProgress: 0,
|
|
|
- allowNewUpload: true,
|
|
|
- error: null,
|
|
|
- recoveredState: null,
|
|
|
- })
|
|
|
+ this.setState({ files: updatedFiles, ...getDefaultUploadState() })
|
|
|
|
|
|
this.emit('reset-progress')
|
|
|
}
|
|
|
|
|
|
+ /** @protected */
|
|
|
+ clearUploadedFiles () {
|
|
|
+ this.setState({ ...getDefaultUploadState(), files: {} })
|
|
|
+ }
|
|
|
+
|
|
|
addPreProcessor (fn) {
|
|
|
this.#preProcessors.add(fn)
|
|
|
}
|
|
@@ -854,11 +860,8 @@ class Uppy {
|
|
|
this.removeFiles(fileIDs, 'cancel-all')
|
|
|
}
|
|
|
|
|
|
- this.setState({
|
|
|
- totalProgress: 0,
|
|
|
- error: null,
|
|
|
- recoveredState: null,
|
|
|
- })
|
|
|
+ this.setState(getDefaultUploadState())
|
|
|
+ // todo should we call this.emit('reset-progress') like we do for resetProgress?
|
|
|
}
|
|
|
}
|
|
|
|